From 98272a9105e68bde10a790eb09b1a5ee6675411f Mon Sep 17 00:00:00 2001 From: "xjin.gao@quectel.com" Date: Mon, 19 Aug 2024 15:12:56 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20pick=209bac79a=20from=20https://gitee.?= =?UTF-8?q?com/qpy-doc-center/teedoc=5Fwith=5Fqpydoc/pulls/407=20=20?= =?UTF-8?q?(umqtt):=20=E6=96=87=E6=A1=A3=E5=A2=9E=E5=8A=A0MQTTClient.wait?= =?UTF-8?q?=5Fmsg=E9=87=8D=E8=A6=81=E4=BA=8B=E9=A1=B9=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0demo=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/API_reference/en/networklib/umqtt.md | 14 ++++++++++++++ docs/API_reference/zh/networklib/umqtt.md | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/docs/API_reference/en/networklib/umqtt.md b/docs/API_reference/en/networklib/umqtt.md index 40e42e56..9439f301 100644 --- a/docs/API_reference/en/networklib/umqtt.md +++ b/docs/API_reference/en/networklib/umqtt.md @@ -251,6 +251,8 @@ MQTTClient.wait_msg() Blocks waiting for a message response from the MQTT server. +>If this method is called in a thread, it is necessary to ensure that the thread stack created is >= 16K. For details, please refer to the mqtt reconnection sample code. + * Parameter None @@ -381,6 +383,7 @@ import net import _thread import checkNet import dataCall +import uos from umqtt import MQTTClient PROJECT_NAME = "QuecPython_MQTT_example" @@ -552,7 +555,18 @@ class MqttClient(): return -1 def loop_forever(self): + task_stacksize =_thread.stack_size() + name,platform = uos.uname()[1].split("=",1) + if platform == "EC600E" or platform == "EC800E": + _thread.stack_size(8 * 1024) + elif platform == "FCM362K": + _thread.stack_size(3 * 1024) + else: + _thread.stack_size(16 * 1024) + # Before creating a thread, modify the thread stack space according to the platform. _thread.start_new_thread(self.__listen, ()) + # After the thread is created successfully, the platform thread stack default size is restored. + _thread.stack_size(task_stacksize) if __name__ == '__main__': ''' diff --git a/docs/API_reference/zh/networklib/umqtt.md b/docs/API_reference/zh/networklib/umqtt.md index 5358e766..00a6b029 100644 --- a/docs/API_reference/zh/networklib/umqtt.md +++ b/docs/API_reference/zh/networklib/umqtt.md @@ -222,6 +222,7 @@ MQTTClient.wait_msg() 阻塞等待服务器消息响应。 +>该方法如果在线程中调用时,需保证创建线程栈空间>=16K,具体请参照mqtt重连示例代码. ### `MQTTClient.get_mqttsta` @@ -339,6 +340,7 @@ import net import _thread import checkNet import dataCall +import uos from umqtt import MQTTClient PROJECT_NAME = "QuecPython_MQTT_example" @@ -510,7 +512,18 @@ class MqttClient(): return -1 def loop_forever(self): + task_stacksize =_thread.stack_size() + name,platform = uos.uname()[1].split("=",1) + if platform == "EC600E" or platform == "EC800E": + _thread.stack_size(8 * 1024) + elif platform == "FCM362K": + _thread.stack_size(3 * 1024) + else: + _thread.stack_size(16 * 1024) + # 创建线程之前,按照平台,修改线程栈空间。 _thread.start_new_thread(self.__listen, ()) + # 线程创建成功后,恢复平台线程栈默认大小。 + _thread.stack_size(task_stacksize) if __name__ == '__main__': ''' -- Gitee