本文整理汇总了Python中tornado.platform.twisted.TwistedIOLoop.add_callback方法的典型用法代码示例。如果您正苦于以下问题:Python TwistedIOLoop.add_callback方法的具体用法?Python TwistedIOLoop.add_callback怎么用?Python TwistedIOLoop.add_callback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.platform.twisted.TwistedIOLoop
的用法示例。
在下文中一共展示了TwistedIOLoop.add_callback方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def __init__(self, io_loop=None):
if not io_loop:
io_loop = tornado.ioloop.IOLoop.current()
self._io_loop = io_loop
self._readers = {} # map of reader objects to fd
self._writers = {} # map of writer objects to fd
self._fds = {} # a map of fd to a (reader, writer) tuple
self._delayedCalls = {}
PosixReactorBase.__init__(self)
self.addSystemEventTrigger('during', 'shutdown', self.crash)
# IOLoop.start() bypasses some of the reactor initialization.
# Fire off the necessary events if they weren't already triggered
# by reactor.run().
def start_if_necessary():
if not self._started:
self.fireSystemEvent('startup')
self._io_loop.add_callback(start_if_necessary)
# IReactorTime
示例2: callFromThread
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def callFromThread(self, f, *args, **kw):
assert callable(f), "%s is not callable" % f
with NullContext():
# This NullContext is mainly for an edge case when running
# TwistedIOLoop on top of a TornadoReactor.
# TwistedIOLoop.add_callback uses reactor.callFromThread and
# should not pick up additional StackContexts along the way.
self._io_loop.add_callback(f, *args, **kw)
# We don't need the waker code from the super class, Tornado uses
# its own waker.
示例3: stop
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def stop(self):
PosixReactorBase.stop(self)
fire_shutdown = functools.partial(self.fireSystemEvent, "shutdown")
self._io_loop.add_callback(fire_shutdown)
示例4: add_callback
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def add_callback(self, callback, *args, **kwargs):
self.reactor.callFromThread(
self._run_callback,
functools.partial(wrap(callback), *args, **kwargs))
示例5: add_callback_from_signal
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def add_callback_from_signal(self, callback, *args, **kwargs):
self.add_callback(callback, *args, **kwargs)
示例6: callFromThread
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def callFromThread(self, f, *args, **kw):
"""See `twisted.internet.interfaces.IReactorThreads.callFromThread`"""
assert callable(f), "%s is not callable" % f
with NullContext():
# This NullContext is mainly for an edge case when running
# TwistedIOLoop on top of a TornadoReactor.
# TwistedIOLoop.add_callback uses reactor.callFromThread and
# should not pick up additional StackContexts along the way.
self._io_loop.add_callback(f, *args, **kw)
# We don't need the waker code from the super class, Tornado uses
# its own waker.
示例7: add_callback
# 需要导入模块: from tornado.platform.twisted import TwistedIOLoop [as 别名]
# 或者: from tornado.platform.twisted.TwistedIOLoop import add_callback [as 别名]
def add_callback(self, callback, *args, **kwargs):
self.reactor.callFromThread(self._run_callback,
wrap(callback), *args, **kwargs)