本文整理匯總了Python中zmq.eventloop.ioloop.IOLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python ioloop.IOLoop方法的具體用法?Python ioloop.IOLoop怎麽用?Python ioloop.IOLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zmq.eventloop.ioloop
的用法示例。
在下文中一共展示了ioloop.IOLoop方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: flush
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def flush(self, timeout=1.0):
"""Immediately processes all pending messages on the iopub channel.
Callers should use this method to ensure that :method:`call_handlers`
has been called for all messages that have been received on the
0MQ SUB socket of this channel.
This method is thread safe.
Parameters
----------
timeout : float, optional
The maximum amount of time to spend flushing, in seconds. The
default is one second.
"""
# We do the IOLoop callback process twice to ensure that the IOLoop
# gets to perform at least one full poll.
stop_time = time.time() + timeout
for i in xrange(2):
self._flushed = False
self.ioloop.add_callback(self._flush)
while not self._flushed and time.time() < stop_time:
time.sleep(0.01)
示例2: __init__
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def __init__(self, queue):
self.queue = queue
self.io_loop = IOLoop(make_current=False)
context = zmq.Context.instance()
self.pause_socket = context.socket(zmq.REP)
self.pause_socket_port = self.pause_socket.bind_to_random_port(
"tcp://127.0.0.1")
self.status_socket = context.socket(zmq.PULL)
self.status_socket_port = self.status_socket.bind_to_random_port(
"tcp://127.0.0.1")
self.pause_stream = ZMQStream(self.pause_socket, self.io_loop)
self.status_stream = ZMQStream(self.status_socket, self.io_loop)
self.pause_stream.on_recv(self.recv_pause)
self.status_stream.on_recv(self.recv_status)
self.thread = threading.Thread(target=self._thread_main)
self.thread.daemon = True
示例3: test_simple
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_simple(self):
"""simple IOLoop creation test"""
loop = ioloop.IOLoop()
loop.make_current()
dc = ioloop.PeriodicCallback(loop.stop, 200)
pc = ioloop.PeriodicCallback(lambda : None, 10)
pc.start()
dc.start()
t = Delay(loop.stop,1)
t.start()
loop.start()
if t.isAlive():
t.abort()
else:
self.fail("IOLoop failed to exit")
示例4: test_instance
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_instance(self):
"""Green IOLoop.instance returns the right object"""
loop = ioloop.IOLoop.instance()
assert isinstance(loop, ioloop.IOLoop)
base_loop = BaseIOLoop.instance()
assert base_loop is loop
示例5: test_current
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_current(self):
"""Green IOLoop.current returns the right object"""
loop = ioloop.IOLoop.current()
assert isinstance(loop, ioloop.IOLoop)
base_loop = BaseIOLoop.current()
assert base_loop is loop
示例6: test_close_all
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_close_all(self):
"""Test close(all_fds=True)"""
loop = ioloop.IOLoop.instance()
req,rep = self.create_bound_pair(zmq.REQ, zmq.REP)
loop.add_handler(req, lambda msg: msg, ioloop.IOLoop.READ)
loop.add_handler(rep, lambda msg: msg, ioloop.IOLoop.READ)
self.assertEqual(req.closed, False)
self.assertEqual(rep.closed, False)
loop.close(all_fds=True)
self.assertEqual(req.closed, True)
self.assertEqual(rep.closed, True)
示例7: _queue_send
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def _queue_send(self, msg):
"""Queue a message to be sent from the IOLoop's thread.
Parameters
----------
msg : message to send
This is threadsafe, as it uses IOLoop.add_callback to give the loop's
thread control of the action.
"""
def thread_send():
self.session.send(self.stream, msg)
self.ioloop.add_callback(thread_send)
示例8: __init__
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def __init__(self, context, session, address):
super(ShellChannel, self).__init__(context, session, address)
self.ioloop = ioloop.IOLoop()
示例9: test_simple
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_simple(self):
"""simple IOLoop creation test"""
loop = self.IOLoop()
loop.make_current()
dc = ioloop.PeriodicCallback(loop.stop, 200)
pc = ioloop.PeriodicCallback(lambda : None, 10)
pc.start()
dc.start()
t = Delay(loop.stop,1)
t.start()
loop.start()
if t.isAlive():
t.abort()
else:
self.fail("IOLoop failed to exit")
示例10: test_instance
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_instance(self):
"""IOLoop.instance returns the right object"""
loop = self.IOLoop.instance()
if not t5asyncio:
assert isinstance(loop, self.IOLoop)
base_loop = BaseIOLoop.instance()
assert base_loop is loop
示例11: test_current
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_current(self):
"""IOLoop.current returns the right object"""
loop = ioloop.IOLoop.current()
if not t5asyncio:
assert isinstance(loop, self.IOLoop)
base_loop = BaseIOLoop.current()
assert base_loop is loop
示例12: test_close_all
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def test_close_all(self):
"""Test close(all_fds=True)"""
loop = self.IOLoop.current()
req,rep = self.create_bound_pair(zmq.REQ, zmq.REP)
loop.add_handler(req, lambda msg: msg, ioloop.IOLoop.READ)
loop.add_handler(rep, lambda msg: msg, ioloop.IOLoop.READ)
self.assertEqual(req.closed, False)
self.assertEqual(rep.closed, False)
loop.close(all_fds=True)
self.assertEqual(req.closed, True)
self.assertEqual(rep.closed, True)
示例13: xtest_instance
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def xtest_instance(self):
"""Green IOLoop.instance returns the right object"""
loop = self.IOLoop.instance()
if not t5asyncio:
assert isinstance(loop, self.IOLoop)
base_loop = BaseIOLoop.instance()
assert base_loop is loop
示例14: launch_scheduler
# 需要導入模塊: from zmq.eventloop import ioloop [as 別名]
# 或者: from zmq.eventloop.ioloop import IOLoop [as 別名]
def launch_scheduler(in_addr, out_addr, mon_addr, not_addr, reg_addr, config=None,
logname='root', log_url=None, loglevel=logging.DEBUG,
identity=b'task', in_thread=False):
ZMQStream = zmqstream.ZMQStream
if config:
# unwrap dict back into Config
config = Config(config)
if in_thread:
# use instance() to get the same Context/Loop as our parent
ctx = zmq.Context.instance()
loop = ioloop.IOLoop.instance()
else:
# in a process, don't use instance()
# for safety with multiprocessing
ctx = zmq.Context()
loop = ioloop.IOLoop()
ins = ZMQStream(ctx.socket(zmq.ROUTER),loop)
util.set_hwm(ins, 0)
ins.setsockopt(zmq.IDENTITY, identity + b'_in')
ins.bind(in_addr)
outs = ZMQStream(ctx.socket(zmq.ROUTER),loop)
util.set_hwm(outs, 0)
outs.setsockopt(zmq.IDENTITY, identity + b'_out')
outs.bind(out_addr)
mons = zmqstream.ZMQStream(ctx.socket(zmq.PUB),loop)
util.set_hwm(mons, 0)
mons.connect(mon_addr)
nots = zmqstream.ZMQStream(ctx.socket(zmq.SUB),loop)
nots.setsockopt(zmq.SUBSCRIBE, b'')
nots.connect(not_addr)
querys = ZMQStream(ctx.socket(zmq.DEALER),loop)
querys.connect(reg_addr)
# setup logging.
if in_thread:
log = Application.instance().log
else:
if log_url:
log = connect_logger(logname, ctx, log_url, root="scheduler", loglevel=loglevel)
else:
log = local_logger(logname, loglevel)
scheduler = TaskScheduler(client_stream=ins, engine_stream=outs,
mon_stream=mons, notifier_stream=nots,
query_stream=querys,
loop=loop, log=log,
config=config)
scheduler.start()
if not in_thread:
try:
loop.start()
except KeyboardInterrupt:
scheduler.log.critical("Interrupted, exiting...")