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


Python threads.deferToThread方法代码示例

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


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

示例1: connectionMade

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def connectionMade(self):
        self._sendSASLMessage(self.START, self.sasl.mechanism)
        initial_message = yield deferToThread(self.sasl.process)
        self._sendSASLMessage(self.OK, initial_message)

        while True:
            status, challenge = yield self._receiveSASLMessage()
            if status == self.OK:
                response = yield deferToThread(self.sasl.process, challenge)
                self._sendSASLMessage(self.OK, response)
            elif status == self.COMPLETE:
                if not self.sasl.complete:
                    msg = "The server erroneously indicated that SASL " \
                          "negotiation was complete"
                    raise TTransport.TTransportException(msg, message=msg)
                else:
                    break
            else:
                msg = "Bad SASL negotiation status: %d (%s)" % (status, challenge)
                raise TTransport.TTransportException(msg, message=msg)

        self._sasl_negotiation_deferred = None
        ThriftClientProtocol.connectionMade(self) 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:25,代码来源:TTwisted.py

示例2: test_http_json

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_http_json(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in JSON format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    data = {
        'temperature': 25.26,
        'humidity': 51.8,
    }
    yield threads.deferToThread(http_json_sensor, settings.channel_path_data, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    del record['time']
    assert record == {u'temperature': 25.26, u'humidity': 51.8}
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:23,代码来源:test_daq_http.py

示例3: test_http_urlencoded

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_http_urlencoded(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in ``x-www-form-urlencoded`` format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    data = {
        'temperature': 25.26,
        'humidity': 51.8,
    }
    yield threads.deferToThread(http_form_sensor, settings.channel_path_data, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    del record['time']
    assert record == {u'temperature': 25.26, u'humidity': 51.8}
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:23,代码来源:test_daq_http.py

示例4: test_http_csv

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_http_csv(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in CSV format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    data = {
        'temperature': 25.26,
        'humidity': 51.8,
    }
    yield threads.deferToThread(http_csv_sensor, settings.channel_path_data, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    del record['time']
    assert record == {u'temperature': 25.26, u'humidity': 51.8}
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:23,代码来源:test_daq_http.py

示例5: test_weewx_mqtt

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_weewx_mqtt(machinery, create_influxdb, reset_influxdb):
    """
    Publish single reading in JSON format to MQTT broker
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    yield threads.deferToThread(mqtt_json_sensor, settings.mqtt_topic_json, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()

    assert record["time"] == '2017-04-17T22:15:00Z'

    assert record["outTemp_C"] == 3.55555555556
    assert record["windSpeed10_kph"] == 5.78725803977
    assert record["cloudbase_meter"] == 773.082217509
    assert record["consBatteryVoltage_volt"] == 4.72

    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:25,代码来源:test_weewx.py

示例6: test_mqtt_legacy

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_mqtt_legacy(machinery, create_influxdb, reset_influxdb):
    """
    Publish single reading in JSON format to MQTT broker on legacy suffix
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    data = {
        'temperature': 42.84,
        'humidity': 83.1,
    }
    yield threads.deferToThread(mqtt_json_sensor, settings.mqtt_topic_json_legacy, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    assert 'temperature' in record or 'humidity' in record 
开发者ID:daq-tools,项目名称:kotori,代码行数:21,代码来源:test_daq_mqtt.py

示例7: test_mqtt_to_influxdb_single

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_mqtt_to_influxdb_single(machinery, create_influxdb, reset_influxdb):
    """
    Publish discrete values to the MQTT broker and
    and proof they are stored in the InfluxDB database.
    """

    # Submit discrete measurement values, without timestamp.
    topic_temperature = settings.mqtt_topic_single + '/temperature'
    topic_humidity = settings.mqtt_topic_single + '/humidity'
    yield threads.deferToThread(mqtt_sensor, topic_temperature, 42.84)
    yield threads.deferToThread(mqtt_sensor, topic_humidity, 83.1)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    assert 'temperature' in record or 'humidity' in record 
开发者ID:daq-tools,项目名称:kotori,代码行数:20,代码来源:test_daq_mqtt.py

示例8: test_mqtt_homie

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_mqtt_homie(machinery, create_influxdb, reset_influxdb):
    """
    Publish reading like a Homie device in JSON format to MQTT broker
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    data = {
        'temperature': 42.84,
        'humidity': 83.1,
    }
    yield threads.deferToThread(mqtt_json_sensor, settings.mqtt_topic_homie, data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    del record['time']
    assert record == {u'humidity': 83.1, u'temperature': 42.84}
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:23,代码来源:test_homie.py

示例9: test_airrohr_http_json

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_airrohr_http_json(machinery, create_influxdb, reset_influxdb):
    """
    Submit single reading in Airrohr JSON format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single measurement, without timestamp.
    yield threads.deferToThread(http_json_sensor, settings.channel_path_airrohr, data_in)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that data arrived in InfluxDB.
    record = influx_sensors.get_first_record()
    del record['time']
    assert record == data_out
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:19,代码来源:test_airrohr.py

示例10: test_event_http_json

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_event_http_json(machinery, create_influxdb, reset_influxdb):
    """
    Submit event in JSON format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single event, without timestamp.
    yield threads.deferToThread(http_json_sensor, settings.channel_path_event, event_data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that event arrived in InfluxDB.
    record = influx_events.get_first_record()
    del record['time']
    assert record == event_data
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:19,代码来源:test_daq_events.py

示例11: test_event_http_urlencoded

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_event_http_urlencoded(machinery, create_influxdb, reset_influxdb):
    """
    Submit event in ``x-www-form-urlencoded`` format to HTTP API
    and proof it is stored in the InfluxDB database.
    """

    # Submit a single event, without timestamp.
    yield threads.deferToThread(http_form_sensor, settings.channel_path_event, event_data)

    # Wait for some time to process the message.
    yield sleep(PROCESS_DELAY)

    # Proof that event arrived in InfluxDB.
    record = influx_events.get_first_record()
    del record['time']
    assert record == event_data
    yield record 
开发者ID:daq-tools,项目名称:kotori,代码行数:19,代码来源:test_daq_events.py

示例12: _read_handshake

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def _read_handshake(self, data):
        """
        Read handshake message, parse the other peer's public key and
        schedule the key exchange for execution outside of the event loop.
        """

        log_prefix = "obfs3:_read_handshake()"
        if len(data) < PUBKEY_LEN:
            log.debug("%s: Not enough bytes for key (%d)." % (log_prefix, len(data)))
            return

        log.debug("%s: Got %d bytes of handshake data (waiting for key)." % (log_prefix, len(data)))

        # Get the public key from the handshake message, do the DH and
        # get the shared secret.
        other_pubkey = data.read(PUBKEY_LEN)

        # Do the UniformDH handshake asynchronously
        self.d = threads.deferToThread(self.dh.get_secret, other_pubkey)
        self.d.addCallback(self._read_handshake_post_dh, other_pubkey, data)
        self.d.addErrback(self._uniform_dh_errback, other_pubkey)

        self.state = ST_WAIT_FOR_HANDSHAKE 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:obfs3.py

示例13: test_deferredFailureAfterSuccess

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_deferredFailureAfterSuccess(self):
        """
        Check that a successful L{threads.deferToThread} followed by a one
        that raises an exception correctly result as a failure.
        """
        # set up a condition that causes cReactor to hang. These conditions
        # can also be set by other tests when the full test suite is run in
        # alphabetical order (test_flow.FlowTest.testThreaded followed by
        # test_internet.ReactorCoreTestCase.testStop, to be precise). By
        # setting them up explicitly here, we can reproduce the hang in a
        # single precise test case instead of depending upon side effects of
        # other tests.
        #
        # alas, this test appears to flunk the default reactor too

        d = threads.deferToThread(lambda: None)
        d.addCallback(lambda ign: threads.deferToThread(lambda: 1//0))
        return self.assertFailure(d, ZeroDivisionError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_threads.py

示例14: test_runs_command

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_runs_command(self):
        """
        ``run()`` on a SSH ``ProcessNode`` runs the command on the machine
        being ssh'd into.
        """
        node = make_sshnode(self)
        temp_file = FilePath(self.mktemp())

        def go():
            with node.run([b"python", b"-c",
                           b"file('%s', 'w').write(b'hello')"
                           % (temp_file.path,)]):
                pass
            return temp_file.getContent()
        d = deferToThread(go)

        def got_data(data):
            self.assertEqual(data, b"hello")
        d.addCallback(got_data)
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:22,代码来源:test_ipc.py

示例15: test_run_stdin

# 需要导入模块: from twisted.internet import threads [as 别名]
# 或者: from twisted.internet.threads import deferToThread [as 别名]
def test_run_stdin(self):
        """
        ``run()`` on a SSH ``ProcessNode`` writes to the remote command's
        stdin.
        """
        node = make_sshnode(self)
        temp_file = FilePath(self.mktemp())

        def go():
            with node.run([b"python", b"-c",
                           b"import sys; "
                           b"file('%s', 'wb').write(sys.stdin.read())"
                           % (temp_file.path,)]) as stdin:
                stdin.write(b"hello ")
                stdin.write(b"there")
            return temp_file.getContent()
        d = deferToThread(go)

        def got_data(data):
            self.assertEqual(data, b"hello there")
        d.addCallback(got_data)
        return d 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_ipc.py


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