本文整理汇总了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)