我正在使用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)