paho.mqtt.python
paho.mqtt.python copied to clipboard
Slow on_message callback causes disconnection
def on_message(client, userdata, msg):
# slow operation ... maybe it needs 5 minutes
then, I got this from mosquitto:
1556772590: Client 417c5720-d208-4a0c-a60f-264b2bf91e8b has exceeded timeout, disconnecting.
1556772590: Socket error on client 417c5720-d208-4a0c-a60f-264b2bf91e8b, disconnecting.
Is this intended?
btw, i have a problem like you. I want to create monitoring subscribing. When the message comes to late in 1 minute, I want to show a warning. I create publisher every one minute post to mqtt. How to know if we got late subscribe from last publish?
00:10 Post A -> Get subscribe A (same time) 00:11 Post B -> - 00:12 Post C ->
Before I do Post C, I didn't get subscribe Post B. How do I know if I didn't get subscribe from Post B?
Regards
@iblis17 Yes this is the intended behaviour. If you have a task which takes a lot of time, execute that task in a separate thread.
I had the same problems but instead of running my task on another thread I switched from calling loop() to loop_start(), which is advertised to run on its own thread.
It resolved the problem for me, but please let me know if I'm doing something stupid.
I'm going to close this due to age/inactivity. As mentioned above the callbacks are not intended for long running actions (start a thread for these). Long callbacks prevent other processes from running and may lead to timeouts.