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