当前位置: 首页>>代码示例>>Python>>正文


Python reactor.callInThread方法代码示例

本文整理汇总了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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_threads.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_threads.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:26,代码来源:test_threads.py

示例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) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:26,代码来源:test_threads.py

示例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 
开发者ID:derekstavis,项目名称:python-sysfs-gpio,代码行数:19,代码来源:gpio.py

示例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)) 
开发者ID:byt3bl33d3r,项目名称:pth-toolkit,代码行数:18,代码来源:test_spinner.py

示例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) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:21,代码来源:test_threads.py

示例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) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:21,代码来源:test_threads.py

示例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 
开发者ID:opencord,项目名称:voltha,代码行数:20,代码来源:connection_mgr.py

示例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 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:12,代码来源:snapd_resource.py

示例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) 
开发者ID:daq-tools,项目名称:kotori,代码行数:11,代码来源:twisted.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:threads.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_internet.py

示例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) 
开发者ID:gdanezis,项目名称:rscoin,代码行数:6,代码来源:rsc.py

示例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) 
开发者ID:grei-ufc,项目名称:pade,代码行数:4,代码来源:common.py


注:本文中的twisted.internet.reactor.callInThread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。