本文整理汇总了Python中twisted.internet.reactor.callInThread方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.callInThread方法的具体用法?Python reactor.callInThread怎么用?Python reactor.callInThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.callInThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_callInThread
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_callInThread(self):
"""
Test callInThread functionality: set a C{threading.Event}, and check
that it's not in the main thread.
"""
def cb(ign):
waiter = threading.Event()
result = []
def threadedFunc():
result.append(threadable.isInIOThread())
waiter.set()
reactor.callInThread(threadedFunc)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event.")
else:
self.assertEqual(result, [False])
return self._waitForThread().addCallback(cb)
示例2: test_callFromThread
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_callFromThread(self):
"""
Test callFromThread functionality: from the main thread, and from
another thread.
"""
def cb(ign):
firedByReactorThread = defer.Deferred()
firedByOtherThread = defer.Deferred()
def threadedFunc():
reactor.callFromThread(firedByOtherThread.callback, None)
reactor.callInThread(threadedFunc)
reactor.callFromThread(firedByReactorThread.callback, None)
return defer.DeferredList(
[firedByReactorThread, firedByOtherThread],
fireOnOneErrback=True)
return self._waitForThread().addCallback(cb)
示例3: test_wakerOverflow
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_wakerOverflow(self):
"""
Try to make an overflow on the reactor waker using callFromThread.
"""
def cb(ign):
self.failure = None
waiter = threading.Event()
def threadedFunction():
# Hopefully a hundred thousand queued calls is enough to
# trigger the error condition
for i in xrange(100000):
try:
reactor.callFromThread(lambda: None)
except:
self.failure = failure.Failure()
break
waiter.set()
reactor.callInThread(threadedFunction)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event")
if self.failure is not None:
return defer.fail(self.failure)
return self._waitForThread().addCallback(cb)
示例4: test_wakerOverflow
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_wakerOverflow(self):
"""
Try to make an overflow on the reactor waker using callFromThread.
"""
def cb(ign):
self.failure = None
waiter = threading.Event()
def threadedFunction():
# Hopefully a hundred thousand queued calls is enough to
# trigger the error condition
for i in range(100000):
try:
reactor.callFromThread(lambda: None)
except:
self.failure = failure.Failure()
break
waiter.set()
reactor.callInThread(threadedFunction)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event")
if self.failure is not None:
return defer.fail(self.failure)
return self._waitForThread().addCallback(cb)
示例5: __new__
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):
instance = super(Controller, cls).__new__(cls)
instance._allocated_pins = {}
instance._poll_queue = select.epoll()
instance._available_pins = []
instance._running = True
# Cleanup before stopping reactor
reactor.addSystemEventTrigger('before', 'shutdown', instance.stop)
# Run the EPoll in a Thread, as it blocks.
reactor.callInThread(instance._poll_queue_loop)
cls._instance = instance
return cls._instance
示例6: test_clean_running_threads
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_clean_running_threads(self):
import threading
import time
current_threads = list(threading.enumerate())
reactor = self.make_reactor()
timeout = self.make_timeout()
spinner = self.make_spinner(reactor)
spinner.run(timeout, reactor.callInThread, time.sleep, timeout / 2.0)
# Python before 2.5 has a race condition with thread handling where
# join() does not remove threads from enumerate before returning - the
# thread being joined does the removal. This was fixed in Python 2.5
# but we still support 2.4, so we have to workaround the issue.
# http://bugs.python.org/issue1703448.
self.assertThat(
[thread for thread in threading.enumerate() if thread.isAlive()],
Equals(current_threads))
示例7: test_callInThread
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def test_callInThread(self):
"""
Test callInThread functionality: set a C{threading.Event}, and check
that it's not in the main thread.
"""
def cb(ign):
waiter = threading.Event()
result = []
def threadedFunc():
result.append(threadable.isInIOThread())
waiter.set()
reactor.callInThread(threadedFunc)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event.")
else:
self.assertEquals(result, [False])
return self._waitForThread().addCallback(cb)
示例8: testWakerOverflow
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def testWakerOverflow(self):
self.failure = None
waiter = threading.Event()
def threadedFunction():
# Hopefully a hundred thousand queued calls is enough to
# trigger the error condition
for i in xrange(100000):
try:
reactor.callFromThread(lambda: None)
except:
self.failure = failure.Failure()
break
waiter.set()
reactor.callInThread(threadedFunction)
waiter.wait(120)
if not waiter.isSet():
self.fail("Timed out waiting for event")
if self.failure is not None:
return defer.fail(self.failure)
示例9: start
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def start(self):
if self.running:
return
self.log.debug('starting')
self.running = True
# Start monitoring the vcore grpc channel
reactor.callInThread(self.monitor_vcore_grpc_channel)
# Start monitoring logical devices and manage agents accordingly
reactor.callLater(0, self.monitor_logical_devices)
self.log.info('started')
return self
示例10: render
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def render(self, request):
"""
Fulfill requests by forwarding them to snapd.
We use a synchronous implementation of HTTP over Unix sockets, so we do
the request in a worker thread and have it call request.finish.
"""
cors.config_cors(request)
reactor.callInThread(self.do_snapd_request, request)
return NOT_DONE_YET
示例11: gotProtocol
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def gotProtocol(self, p):
log.info('gotProtocol, connecting {name}', name=self.name)
self.protocol = p
#def later():
d = p.connect(self.name, keepalive=0, cleanStart=True)
d.addCallback(self.subscribe)
#d.addCallback(self.prepareToPublish)
#reactor.callLater(random.randint(2, 7), later)
#reactor.callInThread(later)
示例12: callMultipleInThread
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def callMultipleInThread(tupleList):
"""
Run a list of functions in the same thread.
tupleList should be a list of (function, argsList, kwargsDict) tuples.
"""
from twisted.internet import reactor
reactor.callInThread(_runMultiple, tupleList)
示例13: testWakeUp
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def testWakeUp(self):
# Make sure other threads can wake up the reactor
d = Deferred()
def wake():
time.sleep(0.1)
# callFromThread will call wakeUp for us
reactor.callFromThread(d.callback, None)
reactor.callInThread(wake)
return d
示例14: save
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def save(self, reactor):
if not self.saving_lock:
self.saving_lock = True
reactor.callInThread(self._save)
示例15: __listen_agent
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callInThread [as 别名]
def __listen_agent(self, agent):
reactor.callInThread(self._listen_agent, agent)