本文整理汇总了Python中zmq.eventloop.ioloop.IOLoop.current方法的典型用法代码示例。如果您正苦于以下问题:Python IOLoop.current方法的具体用法?Python IOLoop.current怎么用?Python IOLoop.current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq.eventloop.ioloop.IOLoop
的用法示例。
在下文中一共展示了IOLoop.current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _default_loop
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def _default_loop(self):
loop = IOLoop.current()
if not isinstance(loop, ZMQIOLoop):
raise TypeError(
"Current tornado IOLoop is %r, not a ZMQIOLoop."
" Run `zmq.eventloop.ioloop.install() first." % loop)
return loop
示例2: main1
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main1():
"""Server routine"""
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
loop = IOLoop.current()
#loop.run_sync(lambda: run1('a string'))
loop.run_sync(partial(run1, 'a string'))
示例3: __init__
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def __init__(self, context, socket_type, io_loop=None):
super(Socket, self).__init__(context, socket_type)
self.io_loop = io_loop or IOLoop.current()
self._recv_futures = []
self._send_futures = []
self._state = 0
self._shadow_sock = _zmq.Socket.shadow(self.underlying)
self._init_io_state()
示例4: poll
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def poll(self, timeout=-1):
"""Return a Future for a poll event"""
future = Future()
if timeout == 0:
try:
result = super(Poller, self).poll(0)
except Exception as e:
future.set_exception(e)
else:
future.set_result(result)
return future
loop = IOLoop.current()
# register Future to be called as soon as any event is available on any socket
# only support polling on zmq sockets, for now
watcher = Future()
for socket, mask in self.sockets:
if mask & _zmq.POLLIN:
socket._add_recv_event("poll", future=watcher)
if mask & _zmq.POLLOUT:
socket._add_send_event("poll", future=watcher)
def on_poll_ready(f):
if future.done():
return
if watcher.exception():
future.set_exception(watcher.exception())
else:
try:
result = super(Poller, self).poll(0)
except Exception as e:
future.set_exception(e)
else:
future.set_result(result)
watcher.add_done_callback(on_poll_ready)
if timeout > 0:
# schedule cancel to fire on poll timeout, if any
def trigger_timeout():
if not watcher.done():
watcher.set_result(None)
timeout_handle = loop.call_later(1e-3 * timeout, trigger_timeout)
def cancel_timeout(f):
loop.remove_timeout(timeout_handle)
future.add_done_callback(cancel_timeout)
def cancel_watcher(f):
if not watcher.done():
watcher.cancel()
future.add_done_callback(cancel_watcher)
return future
示例5: main2
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main2():
"""Server routine"""
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
loop = IOLoop.current()
loop.add_callback(partial(run2, 'another string', loop))
loop.start()
print('(main2) after loop.start')
示例6: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
try:
loop = IOLoop.current()
loop.run_sync(partial(run, loop, ))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例7: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) > 1:
sys.exit(__doc__)
zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10001"
try:
loop = IOLoop.current()
loop.run_sync(partial(run, loop, zip_filter))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例8: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
try:
loop = IOLoop.current()
loop.add_callback(partial(run, loop))
loop.start()
except KeyboardInterrupt:
print("\nFinished (interrupted)")
示例9: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) != 1:
sys.exit(__doc__)
ident = args[0]
try:
loop = IOLoop.current()
loop.run_sync(lambda: run(ident))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例10: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) < 1:
sys.exit(__doc__)
zipcodes = args
print('Running async/await version.')
try:
loop = IOLoop.current()
loop.run_sync(partial(run, loop, zipcodes))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例11: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
try:
loop = IOLoop.current()
loop.add_callback(lambda: run())
loop.start()
except KeyboardInterrupt:
print('\nFinished (interrupted)')
sys.exit(0)
示例12: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) != 2:
sys.exit(__doc__)
try:
ident = args[0]
num_workers = int(args[1])
loop = IOLoop.current()
loop.run_sync(partial(run, loop, ident, num_workers, ))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例13: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
"""main function"""
print('(main) starting')
args = sys.argv[1:]
if len(args) != 0:
sys.exit(__doc__)
try:
loop = IOLoop.current()
loop.run_sync(partial(run, loop))
print('(main) after starting run()')
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例14: main
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def main():
args = sys.argv[1:]
if len(args) == 1:
num_requests = int(args[0])
elif len(args) == 0:
num_requests = 10
else:
sys.exit(__doc__)
try:
loop = IOLoop.current()
loop.run_sync(partial(run, loop, num_requests, ))
except KeyboardInterrupt:
print('\nFinished (interrupted)')
示例15: stop
# 需要导入模块: from zmq.eventloop.ioloop import IOLoop [as 别名]
# 或者: from zmq.eventloop.ioloop.IOLoop import current [as 别名]
def stop(self):
"""Stop the timer."""
if self._timeout is not None:
ioloop = IOLoop.current()
ioloop.remove_timeout(self._timeout)
self._timeout = None