本文整理汇总了Python中twisted.internet.interfaces.IReactorThreads方法的典型用法代码示例。如果您正苦于以下问题:Python interfaces.IReactorThreads方法的具体用法?Python interfaces.IReactorThreads怎么用?Python interfaces.IReactorThreads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.interfaces
的用法示例。
在下文中一共展示了interfaces.IReactorThreads方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lotsOfThreadsAreScheduledCorrectly
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def test_lotsOfThreadsAreScheduledCorrectly(self):
"""
L{IReactorThreads.callFromThread} can be used to schedule a large
number of calls in the reactor thread.
"""
def addAndMaybeFinish():
self.counter += 1
if self.counter == 100:
self.deferred.callback(True)
for i in range(100):
self.schedule(addAndMaybeFinish)
return self.deferred
示例2: callFromThread
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def callFromThread(self, f, *args, **kw):
"""
See L{twisted.internet.interfaces.IReactorThreads.callFromThread}.
"""
assert callable(f), "%s is not callable" % (f,)
# lists are thread-safe in CPython, but not in Jython
# this is probably a bug in Jython, but until fixed this code
# won't work in Jython.
self.threadCallQueue.append((f, args, kw))
self.wakeUp()
示例3: getThreadPool
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def getThreadPool(self):
"""
See L{twisted.internet.interfaces.IReactorThreads.getThreadPool}.
"""
if self.threadpool is None:
self._initThreadPool()
return self.threadpool
示例4: callInThread
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def callInThread(self, _callable, *args, **kwargs):
"""
See L{twisted.internet.interfaces.IReactorThreads.callInThread}.
"""
self.getThreadPool().callInThread(_callable, *args, **kwargs)
示例5: suggestThreadPoolSize
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def suggestThreadPoolSize(self, size):
"""
See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}.
"""
self.getThreadPool().adjustPoolsize(maxthreads=size)
示例6: test_lotsOfThreadsAreScheduledCorrectly
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def test_lotsOfThreadsAreScheduledCorrectly(self):
"""
L{IReactorThreads.callFromThread} can be used to schedule a large
number of calls in the reactor thread.
"""
def addAndMaybeFinish():
self.counter += 1
if self.counter == 100:
self.deferred.callback(True)
for i in xrange(100):
self.schedule(addAndMaybeFinish)
return self.deferred
示例7: callFromThread
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def callFromThread(self, f, *args, **kw):
"""See twisted.internet.interfaces.IReactorThreads.callFromThread.
"""
assert callable(f), "%s is not callable" % (f,)
# lists are thread-safe in CPython, but not in Jython
# this is probably a bug in Jython, but until fixed this code
# won't work in Jython.
self.threadCallQueue.append((f, args, kw))
self.wakeUp()
示例8: callInThread
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def callInThread(self, _callable, *args, **kwargs):
"""See twisted.internet.interfaces.IReactorThreads.callInThread.
"""
if self.threadpool is None:
self._initThreadPool()
self.threadpool.callInThread(_callable, *args, **kwargs)
示例9: suggestThreadPoolSize
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def suggestThreadPoolSize(self, size):
"""See twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize.
"""
if size == 0 and not self.threadpool:
return
if not self.threadpool:
self._initThreadPool()
self.threadpool.adjustPoolsize(maxthreads=size)
示例10: _bail
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def _bail(self):
from twisted.internet import reactor
d = defer.Deferred()
reactor.addSystemEventTrigger('after', 'shutdown',
lambda: d.callback(None))
reactor.fireSystemEvent('shutdown') # radix's suggestion
treactor = interfaces.IReactorThreads(reactor, None)
if treactor is not None:
treactor.suggestThreadPoolSize(0)
# As long as TestCase does crap stuff with the reactor we need to
# manually shutdown the reactor here, and that requires util.wait
# :(
# so that the shutdown event completes
unittest.TestCase('mktemp')._wait(d)
示例11: __init__
# 需要导入模块: from twisted.internet import interfaces [as 别名]
# 或者: from twisted.internet.interfaces import IReactorThreads [as 别名]
def __init__(self, ifname: str, clock: IReactorThreads = None):
if clock is None:
clock = reactor
self.clock = clock # type: IReactorThreads
self.ifname = ifname # type: str
self.servers = None # type: set
self.dhcpRequestsDeferredList = None # type: DeferredList
self.deferredDHCPRequests = [] # type: List[Deferred]
self.transaction_id = make_dhcp_transaction_id() # type: bytes