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


Python reactor.callFromThread方法代码示例

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


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

示例1: stop_reactor

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def stop_reactor():
    """Stop the reactor and join the reactor thread until it stops.
    Call this function in teardown at the module or package level to
    reset the twisted system after your tests. You *must* do this if
    you mix tests using these tools and tests using twisted.trial.
    """
    global _twisted_thread

    def stop_reactor():
        '''Helper for calling stop from withing the thread.'''
        reactor.stop()

    reactor.callFromThread(stop_reactor)
    reactor_thread.join()
    for p in reactor.getDelayedCalls():
        if p.active():
            p.cancel()
    _twisted_thread = None 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:20,代码来源:twistedtools.py

示例2: subscribe

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def subscribe(self, *args):
        #d = self.protocol.subscribe("foo/bar/baz", 0)
        log.info(u"Subscribing to topics {subscriptions}. protocol={protocol}", subscriptions=self.subscriptions, protocol=self.protocol)
        for topic in self.subscriptions:
            log.info(u"Subscribing to topic '{topic}'", topic=topic)
            # Topic name **must not** be unicode, so casting to string
            e = self.protocol.subscribe(str(topic), 0)

        log.info(u"Setting callback handler: {callback}", callback=self.callback)
        self.protocol.setPublishHandler(self.on_message_twisted)
        """
        def cb(*args, **kwargs):
            log.info('publishHandler got called: name={name}, args={args}, kwargs={kwargs}', name=self.name, args=args, kwargs=kwargs)
            return reactor.callFromThread(self.callback, *args, **kwargs)
        self.protocol.setPublishHandler(cb)
        """ 
开发者ID:daq-tools,项目名称:kotori,代码行数:18,代码来源:twisted.py

示例3: _start_socket

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def _start_socket(self, id_, payload, callback, private=False):
        if id_ in self._conns:
            return False

        if private:
            factory_url = self.PRIVATE_STREAM_URL
        else:
            factory_url = self.STREAM_URL

        factory = KrakenClientFactory(factory_url, payload=payload)
        factory.base_client = self
        factory.protocol = KrakenClientProtocol
        factory.callback = callback
        factory.reconnect = True
        self.factories[id_] = factory
        reactor.callFromThread(self.add_connection, id_, factory_url) 
开发者ID:krakenfx,项目名称:kraken-wsclient-py,代码行数:18,代码来源:kraken_wsclient_py.py

示例4: test_threadsAreRunInScheduledOrder

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def test_threadsAreRunInScheduledOrder(self):
        """
        Callbacks should be invoked in the order they were scheduled.
        """
        order = []

        def check(_):
            self.assertEqual(order, [1, 2, 3])

        self.deferred.addCallback(check)
        self.schedule(order.append, 1)
        self.schedule(order.append, 2)
        self.schedule(order.append, 3)
        self.schedule(reactor.callFromThread, self.deferred.callback, None)

        return self.deferred 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_internet.py

示例5: test_callFromThread

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [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

示例6: test_wakerOverflow

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [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

示例7: test_callMultiple

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def test_callMultiple(self):
        """
        L{threads.callMultipleInThread} calls multiple functions in a thread.
        """
        L = []
        N = 10
        d = defer.Deferred()

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

        threads.callMultipleInThread([
            (L.append, (i,), {}) for i in xrange(N)
            ] + [(reactor.callFromThread, (finished,), {})])
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_threads.py

示例8: raven_log

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def raven_log(self, event):
        f = event["log_failure"]
        stack = None
        extra = dict()
        tb = f.getTracebackObject()
        if not tb:
            # include the current stack for at least some
            # context. sentry's expecting that "Frames should be
            # sorted from oldest to newest."
            stack = list(iter_stack_frames())[:-5]  # approx.
            extra = dict(no_failure_tb=True)
        extra.update(
            log_format=event.get('log_format'),
            log_namespace=event.get('log_namespace'),
            client_info=event.get('client_info'),
            )
        reactor.callFromThread(
            self.raven_client.captureException,
            exc_info=(f.type, f.value, tb),
            stack=stack,
            extra=extra,
        )
        # just in case
        del tb 
开发者ID:mozilla-services,项目名称:autopush,代码行数:26,代码来源:logging.py

示例9: check_for_sm_finished

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def check_for_sm_finished(sm, monitoring_manager=None):
    from rafcon.core.states.state import StateExecutionStatus
    while sm.root_state.state_execution_status is not StateExecutionStatus.INACTIVE:
        try:
            sm.root_state.concurrency_queue.get(timeout=10.0)
        except Empty as e:
            pass
        # no logger output here to make it easier for the parser
        print("RAFCON live signal")

    sm.root_state.join()

    # stop the network if the monitoring plugin is enabled
    if monitoring_manager:
        from twisted.internet import reactor
        reactor.callFromThread(reactor.stop) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:18,代码来源:start_server.py

示例10: start_stop_state_machine

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def start_stop_state_machine(state_machine, start_state_path, quit_flag):
    from rafcon.utils.gui_functions import call_gui_callback

    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    call_gui_callback(
        state_machine_execution_engine.execute_state_machine_from_path,
        state_machine=state_machine,
        start_state_path=start_state_path,
        wait_for_execution_finished=True
    )

    if reactor_required():
        from twisted.internet import reactor
        reactor.callFromThread(reactor.stop)

    if quit_flag:
        gui_singletons.main_window_controller.get_controller('menu_bar_controller').on_quit_activate(None, None) 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:19,代码来源:start.py

示例11: signal_handler

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def signal_handler(signal, frame):
    global _user_abort

    state_machine_execution_engine = core_singletons.state_machine_execution_engine
    core_singletons.shut_down_signal = signal

    logger.info("Shutting down ...")

    try:
        if not state_machine_execution_engine.finished_or_stopped():
            state_machine_execution_engine.stop()
            state_machine_execution_engine.join(3)  # Wait max 3 sec for the execution to stop
    except Exception:
        logger.exception("Could not stop state machine")

    _user_abort = True

    # shutdown twisted correctly
    if reactor_required():
        from twisted.internet import reactor
        if reactor.running:
            plugins.run_hook("pre_destruction")
            reactor.callFromThread(reactor.stop)

    logging.shutdown() 
开发者ID:DLR-RM,项目名称:RAFCON,代码行数:27,代码来源:start.py

示例12: test_callMultiple

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def test_callMultiple(self):
        """
        L{threads.callMultipleInThread} calls multiple functions in a thread.
        """
        L = []
        N = 10
        d = defer.Deferred()

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

        threads.callMultipleInThread([
            (L.append, (i,), {}) for i in range(N)
            ] + [(reactor.callFromThread, (finished,), {})])
        return d 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:18,代码来源:test_threads.py

示例13: waitForInterrupt

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def waitForInterrupt():
    if signal.getsignal(signal.SIGINT) != signal.default_int_handler:
        raise RuntimeError("Already waiting")

    d = Deferred()

    def fire(*ignored):
        global interrupted
        signal.signal(signal.SIGINT, signal.default_int_handler)
        now = time.time()
        if now - interrupted < 4:
            reactor.callFromThread(lambda: d.errback(Failure(Stop())))
        else:
            interrupted = now
            reactor.callFromThread(d.callback, None)
    signal.signal(signal.SIGINT, fire)
    return d 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:19,代码来源:sqlwatch.py

示例14: pamAuthenticateThread

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def pamAuthenticateThread(service, user, conv):
    def _conv(items):
        from twisted.internet import reactor
        try:
            d = conv(items)
        except:
            import traceback
            traceback.print_exc()
            return
        ev = threading.Event()
        def cb(r):
            ev.r = (1, r)
            ev.set()
        def eb(e):
            ev.r = (0, e)
            ev.set()
        reactor.callFromThread(d.addCallbacks, cb, eb)
        ev.wait()
        done = ev.r
        if done[0]:
            return done[1]
        else:
            raise done[1].type, done[1].value

    return callIntoPAM(service, user, _conv) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:pamauth.py

示例15: run_thread

# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import callFromThread [as 别名]
def run_thread(execute=True):
    """
    Start pdconfd service as a thread.

    This function schedules pdconfd to run as a thread and returns immediately.
    """
    global configManager
    configManager = ConfigManager(settings.PDCONFD_WRITE_DIR, execute)
    reactor.callFromThread(listen, configManager) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:11,代码来源:main.py


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