Azure IoT强制回调函数在新线程中运行

时间:2018-02-20 09:15:23

标签: python azure-iot-hub azure-iot-suite

我正在使用Azure IoT Hub Python API使用 send_event_async(msg,send_callback,cntr)向云发送消息。有没有办法强制在新线程中处理回调函数,以避免中断主线程?

这是我的代码:

from iothub_client import IoTHubTransportProvider, IoTHubMessage

CON_STR = "<con_str>"
PRT = IoTHubTransportProvider.MQTT
TIMEOUT = 10000
MSG_TXT = "{\"deviceId\": \"MyDevice\"}"

def send_callback(message, result, user_context):
    # do some logic
    pass

client = IoTHubClient(CON_STR, PRT)
client.set_option("messageTimeout", TIMEOUT)
cntr = 0
msg = IoTHubMessage(MSG_TXT)
client.send_event_async(msg, send_callback, cntr)

0 个答案:

没有答案