本文整理匯總了Python中tornado.ioloop.PollIOLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python ioloop.PollIOLoop方法的具體用法?Python ioloop.PollIOLoop怎麽用?Python ioloop.PollIOLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.ioloop
的用法示例。
在下文中一共展示了ioloop.PollIOLoop方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_remove_timeout_cleanup
# 需要導入模塊: from tornado import ioloop [as 別名]
# 或者: from tornado.ioloop import PollIOLoop [as 別名]
def test_remove_timeout_cleanup(self):
# Add and remove enough callbacks to trigger cleanup.
# Not a very thorough test, but it ensures that the cleanup code
# gets executed and doesn't blow up. This test is only really useful
# on PollIOLoop subclasses, but it should run silently on any
# implementation.
for i in range(2000):
timeout = self.io_loop.add_timeout(self.io_loop.time() + 3600,
lambda: None)
self.io_loop.remove_timeout(timeout)
# HACK: wait two IOLoop iterations for the GC to happen.
self.io_loop.add_callback(lambda: self.io_loop.add_callback(self.stop))
self.wait()
示例2: test_timeout_with_arguments
# 需要導入模塊: from tornado import ioloop [as 別名]
# 或者: from tornado.ioloop import PollIOLoop [as 別名]
def test_timeout_with_arguments(self):
# This tests that all the timeout methods pass through *args correctly.
results = []
self.io_loop.add_timeout(self.io_loop.time(), results.append, 1)
self.io_loop.add_timeout(datetime.timedelta(seconds=0),
results.append, 2)
self.io_loop.call_at(self.io_loop.time(), results.append, 3)
self.io_loop.call_later(0, results.append, 4)
self.io_loop.call_later(0, self.stop)
self.wait()
# The asyncio event loop does not guarantee the order of these
# callbacks, but PollIOLoop does.
self.assertEqual(sorted(results), [1, 2, 3, 4])
示例3: run_python
# 需要導入模塊: from tornado import ioloop [as 別名]
# 或者: from tornado.ioloop import PollIOLoop [as 別名]
def run_python(self, *statements):
statements = [
'from tornado.ioloop import IOLoop, PollIOLoop',
'classname = lambda x: x.__class__.__name__',
] + list(statements)
args = [sys.executable, '-c', '; '.join(statements)]
return native_str(subprocess.check_output(args)).strip()
示例4: test_default
# 需要導入模塊: from tornado import ioloop [as 別名]
# 或者: from tornado.ioloop import PollIOLoop [as 別名]
def test_default(self):
if asyncio is not None:
# When asyncio is available, it is used by default.
cls = self.run_python('print(classname(IOLoop.current()))')
self.assertEqual(cls, 'AsyncIOMainLoop')
cls = self.run_python('print(classname(IOLoop()))')
self.assertEqual(cls, 'AsyncIOLoop')
else:
# Otherwise, the default is a subclass of PollIOLoop
is_poll = self.run_python(
'print(isinstance(IOLoop.current(), PollIOLoop))')
self.assertEqual(is_poll, 'True')
示例5: initialize
# 需要導入模塊: from tornado import ioloop [as 別名]
# 或者: from tornado.ioloop import PollIOLoop [as 別名]
def initialize(self, **kwargs):
self.real_io_loop = PollIOLoop(make_current=False) # type: ignore
reactor = self.real_io_loop.run_sync(gen.coroutine(TornadoReactor))
super(LayeredTwistedIOLoop, self).initialize(reactor=reactor, **kwargs)
self.add_callback(self.make_current)