python类callFromThread()的实例源码

recipe-286201.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def runCommand(self, tc):
        """Called from the gui thread, pass a ThreadCommand instance to the
        network"""
        reactor.callFromThread(self._doRunCommand, tc)
twisted.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
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.
twisted.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def add_callback(self, callback, *args, **kwargs):
        self.reactor.callFromThread(
            self._run_callback,
            functools.partial(wrap(callback), *args, **kwargs))
twisted.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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.
twisted.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def add_callback(self, callback, *args, **kwargs):
        self.reactor.callFromThread(
            self._run_callback,
            functools.partial(wrap(callback), *args, **kwargs))
twisted.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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.
threads.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _putResultInDeferred(deferred, f, args, kwargs):
    """Run a function and give results to a Deferred."""
    from twisted.internet import reactor
    try:
        result = f(*args, **kwargs)
    except:
        f = failure.Failure()
        reactor.callFromThread(deferred.errback, f)
    else:
        reactor.callFromThread(deferred.callback, result)
threading_latency.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def printResult(self):
        print
        print
        print "callFromThread latency:"
        sum = 0
        for t in self.from_times: sum += t
        print "%f millisecond" % ((sum / self.numRounds) * 1000)

        print "callInThread latency:"
        sum = 0
        for t in self.in_times: sum += t
        print "%f millisecond" % ((sum / self.numRounds) * 1000)
        print
        print
threading_latency.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def tcmf_2(self, start):
        # runs in thread
        self.in_times.append(time.time() - start)
        reactor.callFromThread(self.tcmf_3, time.time())
test_threads.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def testCallFromThread(self):
        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)
test_threads.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testCallMultiple(self):
        L = []
        N = 10
        d = defer.Deferred()

        def finished():
            self.assertEquals(L, range(N))
            d.callback(None)

        threads.callMultipleInThread([
            (L.append, (i,), {}) for i in xrange(N)
            ] + [(reactor.callFromThread, (finished,), {})])
        return d
test_internet.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
test_internet.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _callFromThreadCallback(self, d):
        reactor.callFromThread(self._callFromThreadCallback2, d)
        reactor.callLater(0, self._stopCallFromThreadCallback)
test_internet.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def testCallFromThreadStops(self):
        """
        Ensure that callFromThread from inside a callFromThread
        callback doesn't sit in an infinite loop and lets other
        things happen too.
        """
        self.stopped = False
        d = defer.Deferred()
        reactor.callFromThread(self._callFromThreadCallback, d)
        return d
test_internet.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def schedule(self, *args, **kwargs):
        """Override in subclasses."""
        reactor.callFromThread(*args, **kwargs)
interactive.py 文件源码 项目:packet-queue 作者: google 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __setattr__(self, name, value):
    if name not in self._params:
      raise AttributeError(name)
    reactor.callFromThread(self._params.__setitem__, name, value)
interactive.py 文件源码 项目:packet-queue 作者: google 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def reset(self):
    reactor.callFromThread(self._atomic_reset)
test_api_end_to_end.py 文件源码 项目:python-api 作者: quedexnet 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def tearDown(self):
    reactor.callFromThread(reactor.stop)
network.py 文件源码 项目:bptc_wallet 作者: ceddie 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def stop_reactor_thread():
    """Stop twisted's reactor."""

    reactor.callFromThread(reactor.stop)
launcher.py 文件源码 项目:flowder 作者: amir-khakshour 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def check_storage_path(self):
        if not os.path.exists(self.storage_path):
            try:
                os.makedirs(self.storage_path)
            except OSError as e:
                if e.errno == 13:
                    log.err("Can't create storage directory: access denied")
                else:
                    raise e

                reactor.callFromThread(self.stop)


问题


面经


文章

微信
公众号

扫码关注公众号