本文整理匯總了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)