本文整理汇总了Python中zmq.eventloop方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.eventloop方法的具体用法?Python zmq.eventloop怎么用?Python zmq.eventloop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.eventloop方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_recv_json_cancelled
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [as 别名]
def test_recv_json_cancelled(self):
@gen.coroutine
def test():
a, b = self.create_bound_pair(zmq.PUSH, zmq.PULL)
f = b.recv_json()
assert not f.done()
f.cancel()
# cycle eventloop to allow cancel events to fire
yield gen.sleep(0)
obj = dict(a=5)
yield a.send_json(obj)
with pytest.raises(future.CancelledError):
recvd = yield f
assert f.done()
# give it a chance to incorrectly consume the event
events = yield b.poll(timeout=5)
assert events
yield gen.sleep(0)
# make sure cancelled recv didn't eat up event
recvd = yield gen.with_timeout(timedelta(seconds=5), b.recv_json())
assert recvd == obj
self.loop.run_sync(test)
示例2: enter_eventloop
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [as 别名]
def enter_eventloop(self):
"""enter eventloop"""
self.log.info("entering eventloop")
# restore default_int_handler
signal(SIGINT, default_int_handler)
while self.eventloop is not None:
try:
self.eventloop(self)
except KeyboardInterrupt:
# Ctrl-C shouldn't crash the kernel
self.log.error("KeyboardInterrupt caught in kernel")
continue
else:
# eventloop exited cleanly, this means we should stop (right?)
self.eventloop = None
break
self.log.info("exiting eventloop")
示例3: test_eventloop
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [as 别名]
def test_eventloop(self):
"""test eventloop imports"""
try:
import tornado
except ImportError:
pytest.skip('requires tornado')
import zmq.eventloop
from zmq.eventloop import ioloop
from zmq.eventloop import zmqstream
示例4: run_application
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [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()
示例5: _eventloop_changed
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [as 别名]
def _eventloop_changed(self, name, old, new):
"""schedule call to eventloop from IOLoop"""
loop = ioloop.IOLoop.instance()
loop.add_timeout(time.time()+0.1, self.enter_eventloop)
示例6: do_one_iteration
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import eventloop [as 别名]
def do_one_iteration(self):
"""step eventloop just once"""
InteractiveShell.set_instance(self.shell)
if self.control_stream:
self.control_stream.flush()
for stream in self.shell_streams:
# handle at most one request per iteration
stream.flush(zmq.POLLIN, 1)
stream.flush(zmq.POLLOUT)