本文整理匯總了Python中zmq.eventloop.ioloop.install方法的典型用法代碼示例。如果您正苦於以下問題:Python ioloop.install方法的具體用法?Python ioloop.install怎麽用?Python ioloop.install使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zmq.eventloop.ioloop
的用法示例。
在下文中一共展示了ioloop.install方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_application
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import install [as 別名]
def run_application(options, instance_name):
from zmq.eventloop import ioloop
ioloop.install()
application = WebSocketGatewayApplication(options, instance_name)
server = tornado.httpserver.HTTPServer(application)
server.listen(options.port)
try:
tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
application.clean_up()
示例2: __init__
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import install [as 別名]
def __init__(self, config, driver_info, driver):
# Clone config so we can update it.
config = json.loads(json.dumps(config))
self._config = config
self._exiting = False
self._engine_id = str(uuid.uuid4())
self._wire = WireProtocol(self._engine_id, config["key"], config["signature_scheme"])
connection = config["transport"] + "://" + config["ip"]
def bind(socket, port):
if port <= 0:
return socket.bind_to_random_port(connection)
else:
socket.bind("%s:%s" % (connection, port))
return port
def wrap_with_deserialization(fn):
def accept(wire_msg):
return fn(*self._wire.deserialize_wire_msg(wire_msg))
return accept
## Initialize:
ioloop.install()
ctx = zmq.Context()
self._heartbeat_socket = ctx.socket(zmq.REP)
config["hb_port"] = bind(self._heartbeat_socket, config["hb_port"])
# IOPub/Sub: also called SubSocketChannel in IPython sources
self._iopub_socket = ctx.socket(zmq.PUB)
config["iopub_port"] = bind(self._iopub_socket, config["iopub_port"])
iopub_stream = zmqstream.ZMQStream(self._iopub_socket)
iopub_stream.on_recv(wrap_with_deserialization(self._iopub_handler))
iopub = OutgoingStream(self._wire, iopub_stream)
self._control_socket = ctx.socket(zmq.ROUTER)
config["control_port"] = bind(self._control_socket, config["control_port"])
control_stream = zmqstream.ZMQStream(self._control_socket)
control_stream.on_recv(wrap_with_deserialization(self._control_handler))
self._stdin_socket = ctx.socket(zmq.ROUTER)
config["stdin_port"] = bind(self._stdin_socket, config["stdin_port"])
stdin_stream = zmqstream.ZMQStream(self._stdin_socket)
stdin_stream.on_recv(wrap_with_deserialization(self._stdin_handler))
self._shell_socket = ctx.socket(zmq.ROUTER)
config["shell_port"] = bind(self._shell_socket, config["shell_port"])
shell_stream = zmqstream.ZMQStream(self._shell_socket)
shell = OutgoingStream(self._wire, shell_stream)
shell_stream.on_recv(wrap_with_deserialization(self._shell_handler))
self._shell_handler_impl = ShellHandler(self._engine_id, iopub, shell, driver_info, driver)