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


Python threads.blockingCallFromThread方法代码示例

本文整理汇总了Python中twisted.internet.threads.blockingCallFromThread方法的典型用法代码示例。如果您正苦于以下问题:Python threads.blockingCallFromThread方法的具体用法?Python threads.blockingCallFromThread怎么用?Python threads.blockingCallFromThread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.threads的用法示例。


在下文中一共展示了threads.blockingCallFromThread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fetch

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def fetch(self, request_or_url, spider=None, redirect=True, **kwargs):
        if isinstance(request_or_url, Request):
            request = request_or_url
        else:
            url = any_to_uri(request_or_url)
            request = Request(url, dont_filter=True, **kwargs)
            if redirect:
                request.meta['handle_httpstatus_list'] = SequenceExclude(range(300, 400))
            else:
                request.meta['handle_httpstatus_all'] = True
        response = None
        try:
            response, spider = threads.blockingCallFromThread(
                reactor, self._schedule, request, spider)
        except IgnoreRequest:
            pass
        self.populate_vars(response, request, spider) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:shell.py

示例2: _input_code_with_completion

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _input_code_with_completion(prompt, input_helper, reactor):
    # reminder: this all occurs in a separate thread. All calls to input_helper
    # must go through blockingCallFromThread()
    c = CodeInputter(input_helper, reactor)
    if readline is not None:
        if readline.__doc__ and "libedit" in readline.__doc__:
            readline.parse_and_bind("bind ^I rl_complete")
        else:
            readline.parse_and_bind("tab: complete")
        readline.set_completer(c.completer)
        readline.set_completer_delims("")
        debug("==== readline-based completion is prepared")
    else:
        debug("==== unable to import readline, disabling completion")
    code = input(prompt)
    # Code is str(bytes) on py2, and str(unicode) on py3. We want unicode.
    if isinstance(code, bytes):
        code = code.decode("utf-8")
    c.finish(code)
    return c.used_completion 
开发者ID:warner,项目名称:magic-wormhole,代码行数:22,代码来源:_rlcompleter.py

示例3: _eval

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _eval(deferred, reactor):
        """Evaluate a deferred on a given reactor and return the result

        This function is safe to call with a deferred that has already been evaluated.
        """

        @defer.inlineCallbacks
        def closure():
            if deferred.called:
                result = deferred.result
            else:
                result = yield deferred

            defer.returnValue(result)

        if threading.currentThread().getName() == reactor.thread_name:
            return closure()
        else:
            return threads.blockingCallFromThread(reactor, closure)


#
# Exceptions
# 
开发者ID:digidotcom,项目名称:python-wpa-supplicant,代码行数:26,代码来源:core.py

示例4: connect

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def connect(self):
        """Connect to wpa_supplicant over D-Bus

        :returns: Remote D-Bus proxy object of the root wpa_supplicant interface
        :rtype: :class:`~WpaSupplicant`
        """

        if not self._reactor.running:
            raise ReactorNotRunning('Twisted Reactor must be started (call .run())')

        @defer.inlineCallbacks
        def get_conn():
            self._reactor.thread_name = threading.currentThread().getName()
            conn = yield client.connect(self._reactor, busAddress='system')
            defer.returnValue(conn)

        conn = threads.blockingCallFromThread(self._reactor, get_conn)
        return WpaSupplicant('/fi/w1/wpa_supplicant1', conn, self._reactor, ) 
开发者ID:digidotcom,项目名称:python-wpa-supplicant,代码行数:20,代码来源:core.py

示例5: blocking_call_from_thread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def blocking_call_from_thread(self, callback, timeout):
        """Call the given function from a thread, and wait for the result synchronously
        for as long as the timeout will allow.

        Args:
            callback: Callable function to be invoked from the thread.
            timeout (:obj: int): Number of seconds to wait for the response before
                raising an exception.

        Returns:
            The results from the callback, or a timeout exception.
        """
        result_placeholder = defer.Deferred()
        if timeout:
            result_placeholder.addTimeout(timeout, reactor, onTimeoutCancel=self.raise_timeout_exception)
        return threads.blockingCallFromThread(reactor, callback, result_placeholder) 
开发者ID:gramaziokohler,项目名称:roslibpy,代码行数:18,代码来源:comm_autobahn.py

示例6: _clean

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _clean(self):
        # Spin a bit to flush out imminent delayed calls. It's not clear why
        # we do this: left-over delayed calls are detritus like any other.
        # However, this is done by both testtools and Twisted's trial, and we
        # do it for consistency with them.
        if not self._tickReactor(0.5):
            raise MAASCrochetReactorStalled(
                "Reactor did not respond after 500ms."
            )
        # Ensure that all threadpools are quiet. Do this first because we must
        # crash the whole run if they don't go quiet before the next test.
        dirtyPools, threadStacks = blockingCallFromThread(
            reactor, self._cleanThreads
        )
        if len(dirtyPools) != 0:
            raise MAASCrochetDirtyThreadsError(dirtyPools, threadStacks)
        # Find leftover delayed calls and selectables in use.
        dirtyCalls, dirtySelectables = blockingCallFromThread(
            reactor, self._cleanReactor
        )
        if len(dirtyCalls) != 0 or len(dirtySelectables) != 0:
            raise MAASCrochetDirtyReactorError(dirtyCalls, dirtySelectables) 
开发者ID:maas,项目名称:maas,代码行数:24,代码来源:runtest.py

示例7: _execute

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _execute(self):
        """
        Callback fired when the associated event is set.  Run the C{action}
        callback on the wrapped descriptor in the main reactor thread and raise
        or return whatever it raises or returns to cause this event handler to
        be removed from C{self._reactor} if appropriate.
        """
        return blockingCallFromThread(
            self._reactor, lambda: getattr(self._fd, self._action)()) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:win32eventreactor.py

示例8: _testBlockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _testBlockingCallFromThread(self, reactorFunc):
        """
        Utility method to test L{threads.blockingCallFromThread}.
        """
        waiter = threading.Event()
        results = []
        errors = []
        def cb1(ign):
            def threadedFunc():
                try:
                    r = threads.blockingCallFromThread(reactor, reactorFunc)
                except Exception as e:
                    errors.append(e)
                else:
                    results.append(r)
                waiter.set()

            reactor.callInThread(threadedFunc)
            return threads.deferToThread(waiter.wait, self.getTimeout())

        def cb2(ign):
            if not waiter.isSet():
                self.fail("Timed out waiting for event")
            return results, errors

        return self._waitForThread().addCallback(cb1).addBoth(cb2) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:28,代码来源:test_threads.py

示例9: test_blockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def test_blockingCallFromThread(self):
        """
        Test blockingCallFromThread facility: create a thread, call a function
        in the reactor using L{threads.blockingCallFromThread}, and verify the
        result returned.
        """
        def reactorFunc():
            return defer.succeed("foo")
        def cb(res):
            self.assertEqual(res[0][0], "foo")

        return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_threads.py

示例10: test_asyncBlockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def test_asyncBlockingCallFromThread(self):
        """
        Test blockingCallFromThread as above, but be sure the resulting
        Deferred is not already fired.
        """
        def reactorFunc():
            d = defer.Deferred()
            reactor.callLater(0.1, d.callback, "egg")
            return d
        def cb(res):
            self.assertEqual(res[0][0], "egg")

        return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_threads.py

示例11: test_asyncErrorBlockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def test_asyncErrorBlockingCallFromThread(self):
        """
        Test error report for blockingCallFromThread as above, but be sure the
        resulting Deferred is not already fired.
        """
        def reactorFunc():
            d = defer.Deferred()
            reactor.callLater(0.1, d.errback, RuntimeError("spam"))
            return d
        def cb(res):
            self.assertIsInstance(res[1][0], RuntimeError)
            self.assertEqual(res[1][0].args[0], "spam")

        return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_threads.py

示例12: test_errorBlockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def test_errorBlockingCallFromThread(self):
        """
        Test error report for blockingCallFromThread.
        """
        def reactorFunc():
            return defer.fail(RuntimeError("bar"))
        def cb(res):
            self.assertIsInstance(res[1][0], RuntimeError)
            self.assertEqual(res[1][0].args[0], "bar")

        return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:13,代码来源:test_threads.py

示例13: bcft

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def bcft(self, f, *a, **kw):
        return blockingCallFromThread(self._reactor, f, *a, **kw) 
开发者ID:warner,项目名称:magic-wormhole,代码行数:4,代码来源:_rlcompleter.py

示例14: _testBlockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def _testBlockingCallFromThread(self, reactorFunc):
        """
        Utility method to test L{threads.blockingCallFromThread}.
        """
        waiter = threading.Event()
        results = []
        errors = []
        def cb1(ign):
            def threadedFunc():
                try:
                    r = threads.blockingCallFromThread(reactor, reactorFunc)
                except Exception, e:
                    errors.append(e)
                else: 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:16,代码来源:test_threads.py

示例15: test_blockingCallFromThread

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import blockingCallFromThread [as 别名]
def test_blockingCallFromThread(self):
        """
        Test blockingCallFromThread facility: create a thread, call a function
        in the reactor using L{threads.blockingCallFromThread}, and verify the
        result returned.
        """
        def reactorFunc():
            return defer.succeed("foo")
        def cb(res):
            self.assertEquals(res[0][0], "foo")

        return self._testBlockingCallFromThread(reactorFunc).addCallback(cb) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:14,代码来源:test_threads.py


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