def serve_runtime(runtime=None, host=DEFAULTS['host'], port=DEFAULTS['port'],
registry_host=DEFAULTS['registry_host'],
registry_port=DEFAULTS['registry_port']):
runtime = runtime if runtime is not None else Runtime()
address = 'ws://{}:{:d}'.format(host, port)
def runtime_application_task():
"""
This greenlet runs the websocket server that responds to remote commands
that inspect/manipulate the Runtime.
"""
print('Runtime listening at {}'.format(address))
WebSocketRuntimeApplication.runtimes[port] = runtime
try:
r = geventwebsocket.Resource(
OrderedDict([('/', WebSocketRuntimeApplication)]))
s = geventwebsocket.WebSocketServer(('', port), r)
s.serve_forever()
finally:
WebSocketRuntimeApplication.runtimes.pop(port)
def local_registration_task():
"""
This greenlet will run the rill registry to register the runtime with
the ui.
"""
from rill.registry import serve_registry
serve_registry(registry_host, registry_port, host, port)
tasks = [runtime_application_task, local_registration_task]
# Start!
gevent.wait([gevent.spawn(t) for t in tasks])
评论列表
文章目录