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


Python reactor.callFromThread函数代码示例

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


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

示例1: run

 def run(self):
     while True:
         self.userv.wi_available.acquire()
         while len(self.userv.wi) == 0:
             self.userv.wi_available.wait()
         wi = self.userv.wi.pop(0)
         if wi == None:
             # Shutdown request, relay it further
             self.userv.wi.append(None)
             self.userv.wi_available.notify()
         self.userv.wi_available.release()
         if wi == None:
             break
         command, result_callback, callback_parameters = wi
         try:
             data, rtpc_delay = self.send_raw(command)
             if len(data) == 0:
                 data, rtpc_delay = None, None
         except Exception as e:
             print(e)
             data, rtpc_delay = None, None
         if result_callback != None:
             reactor.callFromThread(self.dispatch, result_callback, data, callback_parameters)
         if rtpc_delay != None:
             reactor.callFromThread(self.userv.register_delay, rtpc_delay)
开发者ID:lemenkov,项目名称:rtpproxy,代码行数:25,代码来源:Rtp_proxy_client_stream.py

示例2: _new_fragment

 def _new_fragment(self, hlssink):
     self.log("hlsink created a new fragment")
     try:
         fragment = hlssink.get_property('fragment')
     except:
         fragment = hlssink.emit('pull-fragment')
     reactor.callFromThread(self._process_fragment, fragment)
开发者ID:micolous,项目名称:flumotion,代码行数:7,代码来源:hlsstreamer.py

示例3: onSettingsChange

    def onSettingsChange(self, plugin_name, data):
        """
        The plugin has been changed by the frontend

        :param plugin_name: Name of plugin that changed
        :type plugin_name: str
        :param data: Complete data (changed and unchanged)
        :type data: dict
        :rtype: None
        """
        logger.info(u"onSettingsChange: {}".format(data))
        if not plugin_name:
            logger.error("Missing plugin name")
            return
        if not data:
            logger.error("Missing data")
            return
        logger.info(u"Sending data {}".format(data))
        reactor.callFromThread(self._sendJSON, {
            'msg': "plugin_data_set",
            'plugin_name': plugin_name,
            'data': data
        })
        # trigger db update
        reactor.callFromThread(self._sendJSON, {
            'msg': "plugin_data_get",
            'plugin_name': plugin_name
        })
开发者ID:the01,项目名称:paps-settings,代码行数:28,代码来源:pluginProtocol.py

示例4: test

 def test(self):
     crawler = mock.MagicMock()
     crawler.settings = CrawlerSettings()
     crawler.settings.overrides['USER_AGENT'] = 'CustomAgent'
     self.assertRaises(NotConfigured, RobotsTxtMiddleware, crawler)
     crawler.settings.overrides['ROBOTSTXT_OBEY'] = True
     crawler.engine.download = mock.MagicMock()
     ROBOTS = re.sub(r'^\s+(?m)', '', '''
     User-Agent: *
     Disallow: /admin/
     Disallow: /static/
     ''')
     response = Response('http://site.local/robots.txt', body=ROBOTS)
     def return_response(request, spider):
         deferred = Deferred()
         reactor.callFromThread(deferred.callback, response)
         return deferred
     crawler.engine.download.side_effect = return_response
     middleware = RobotsTxtMiddleware(crawler)
     spider = None  # not actually used
     # There is a bit of neglect in robotstxt.py: robots.txt is fetched asynchronously,
     # and it is actually fetched only *after* first process_request completes.
     # So, first process_request will always succeed.
     # We defer test() because otherwise robots.txt download mock will be called after assertRaises failure.
     self.assertIsNone(middleware.process_request(Request('http://site.local'), spider))  # not affected by robots.txt
     def test(r):
         self.assertIsNone(middleware.process_request(Request('http://site.local/allowed'), spider))
         self.assertRaises(IgnoreRequest, middleware.process_request, Request('http://site.local/admin/main'), spider)
         self.assertRaises(IgnoreRequest, middleware.process_request, Request('http://site.local/static/'), spider)
     deferred = Deferred()
     deferred.addCallback(test)
     reactor.callFromThread(deferred.callback, None)
     return deferred
开发者ID:dvska,项目名称:scrapy,代码行数:33,代码来源:test_downloadermiddleware_robotstxt.py

示例5: disconnect

    def disconnect(self):
        """ Disconnect from the database.

        This closes all active connections in the underlying
        connection pool, and calls the `on_connection_lost`. """
        self.metadata.bind.dispose()
        reactor.callFromThread(self.on_connection_lost)
开发者ID:alexbrasetvik,项目名称:Piped,代码行数:7,代码来源:db.py

示例6: do_topic

    def do_topic(self, line):
        """"topic [set|get] <roomid> [<newtopic>]"
        Set the topic for a room: topic set <roomid> <newtopic>
        Get the topic for a room: topic get <roomid>
        """
        try:
            args = self._parse(line, ["action", "roomid", "topic"])
            if "action" not in args or "roomid" not in args:
                print "Must specify set|get and a room ID."
                return
            if args["action"].lower() not in ["set", "get"]:
                print "Must specify set|get, not %s" % args["action"]
                return

            path = "/rooms/%s/topic" % urllib.quote(args["roomid"])

            if args["action"].lower() == "set":
                if "topic" not in args:
                    print "Must specify a new topic."
                    return
                body = {
                    "topic": args["topic"]
                }
                reactor.callFromThread(self._run_and_pprint, "PUT", path, body)
            elif args["action"].lower() == "get":
                reactor.callFromThread(self._run_and_pprint, "GET", path)
        except Exception as e:
            print e
开发者ID:0-T-0,项目名称:synapse,代码行数:28,代码来源:console.py

示例7: _send_receipt

 def _send_receipt(self, event, feedback_type):
     path = ("/rooms/%s/messages/%s/%s/feedback/%s/%s" %
            (urllib.quote(event["room_id"]), event["user_id"], event["msg_id"],
             self._usr(), feedback_type))
     data = {}
     reactor.callFromThread(self._run_and_pprint, "PUT", path, data=data,
                            alt_text="Sent receipt for %s" % event["msg_id"])
开发者ID:0-T-0,项目名称:synapse,代码行数:7,代码来源:console.py

示例8: wrapper

 def wrapper(*args, **kargs):
     q = Queue()
     def callback(value):
         q.put(None)
     def errback(failure):
         # Retrieve and save full exception info
         try:
             failure.raiseException()
         except:
             q.put(sys.exc_info())
     def g():
         try:
             d = func(*args, **kargs)
             try:
                 d.addCallbacks(callback, errback)
             # Check for a common mistake and display a nice error
             # message
             except AttributeError:
                 raise TypeError("you must return a twisted Deferred "
                                 "from your test case!")
         # Catch exceptions raised in the test body (from the
         # Twisted thread)
         except:
             q.put(sys.exc_info())
     reactor.callFromThread(g)
     try:
         error = q.get(timeout=timeout)
     except Empty:
         raise TimeExpired("timeout expired before end of test (%f s.)"
                           % timeout)
     # Re-raise all exceptions
     if error is not None:
         exc_type, exc_value, tb = error
         raise exc_type(exc_value).with_traceback(tb)
开发者ID:Hank02,项目名称:posts,代码行数:34,代码来源:twistedtools.py

示例9: writeResponse

 def writeResponse(message):
     global processing, queue
     self.transport.write(message + "\r\n")
     if queue.empty() == False:
         reactor.callFromThread(self.lineReceived, queue.get())
         print "Processing message in Queue"
     processing = False
开发者ID:anthonygillet,项目名称:scripts,代码行数:7,代码来源:twist.py

示例10: run

 def run(self):
     maxemptydata = 100
     while True:
         try:
             data, address = self.userv.skt.recvfrom(8192)
             if not data:
                 # Ugly hack to detect socket being closed under us on Linux.
                 # The problem is that even call on non-closed socket can
                 # sometimes return empty data buffer, making AsyncReceiver
                 # to exit prematurely.
                 maxemptydata -= 1
                 if maxemptydata == 0:
                     break
                 continue
             else:
                 maxemptydata = 100
         except Exception, why:
             if isinstance(why, socket.error) and why[0] in (ECONNRESET, ENOTCONN, ESHUTDOWN):
                 break
             if isinstance(why, socket.error) and why[0] in (EINTR,):
                 continue
             else:
                 print datetime.now(), 'Udp_server: unhandled exception when receiving incoming data'
                 print '-' * 70
                 traceback.print_exc(file = sys.stdout)
                 print '-' * 70
                 sys.stdout.flush()
                 sleep(1)
                 continue
         rtime = MonoTime()
         if self.userv.uopts.family == socket.AF_INET6:
             address = ('[%s]' % address[0], address[1])
         reactor.callFromThread(self.userv.handle_read, data, address, rtime)
开发者ID:JustRight,项目名称:rtpproxy,代码行数:33,代码来源:Udp_server.py

示例11: runTestFunc

 def runTestFunc():
     no_errors = False
     try:
         func(*clients)
         no_errors = True
     finally:
         reactor.callFromThread(superviseFunc, connections, no_errors)
开发者ID:mwicat,项目名称:skinnytest,代码行数:7,代码来源:sccptest.py

示例12: _client_removed_cb

 def _client_removed_cb(self, element, arg0, client_status):
     # treat as error if we were removed because of GST_CLIENT_STATUS_ERROR
     # FIXME: can we use the symbol instead of a numeric constant ?
     if client_status == 4:
         # since we get called from the streaming thread, hand off handling
         # to the reactor's thread
         reactor.callFromThread(self._client_error_cb)
开发者ID:ylatuya,项目名称:Flumotion,代码行数:7,代码来源:disker.py

示例13: _signal_kill

 def _signal_kill(self, signum, _):
     install_shutdown_handlers(signal.SIG_IGN)
     signame = signal_names[signum]
     log.msg(format='Received %(signame)s twice, forcing unclean shutdown',
             level=log.INFO, signame=signame)
     self._stop_logging()
     reactor.callFromThread(self._stop_reactor)
开发者ID:DLBob,项目名称:scrapy,代码行数:7,代码来源:crawler.py

示例14: next

    def next(self):
        """Since QueueReader is iterable, this is the function that runs the
        for-loop and dispatches work to the thread.

        This should be the only thread that executes outside of the Twisted
        main thread.
        """

        # If we just completed a range, we should tell the main thread.
        now = time()
        if self.currentData:
            dt = now - self.startedAt
            # self.currentData[1] is the un-preprocessed NonceRange.
            reactor.callFromThread(self._ranExecution, dt, self.currentData[1])
        self.startedAt = now

        # Block for more data from the main thread. In 99% of cases, though,
        # there should already be something here.
        # Note that this comes back with either a tuple, or a StopIteration()
        self.currentData = self.dataQueue.get(True)

        # Does the main thread want us to shut down, or pass some more data?
        if isinstance(self.currentData, StopIteration):
            raise self.currentData

        # We just took the only item in the queue. It needs to be restocked.
        reactor.callFromThread(self._requestMore)

        # currentData is actually a tuple, with item 0 intended for the kernel.
        return self.currentData[0]
开发者ID:Blizzard-,项目名称:Phoenix-Miner,代码行数:30,代码来源:QueueReader.py

示例15: do_register

    def do_register(self, line):
        """Registers for a new account: "register <userid> <noupdate>"
        <userid> : The desired user ID
        <noupdate> : Do not automatically clobber config values.
        """
        args = self._parse(line, ["userid", "noupdate"])

        password = None
        pwd = None
        pwd2 = "_"
        while pwd != pwd2:
            pwd = getpass.getpass("Type a password for this user: ")
            pwd2 = getpass.getpass("Retype the password: ")
            if pwd != pwd2 or len(pwd) == 0:
                print "Password mismatch."
                pwd = None
            else:
                password = pwd

        body = {
            "type": "m.login.password"
        }
        if "userid" in args:
            body["user"] = args["userid"]
        if password:
            body["password"] = password

        reactor.callFromThread(self._do_register, body,
                               "noupdate" not in args)
开发者ID:0-T-0,项目名称:synapse,代码行数:29,代码来源:console.py


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