-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python MQTT client hangs without error after a few hundred writes #47
Comments
Hi, i dont know if this is helpful for your case but it may be an explaination to the behavior you describe. We noticed in our application that if the connection goes down and we are using "success = result.get() == TBPublishInfo.TB_ERR_SUCCESS" to check the transmission (which is also documented as a blocking call) it will hang indefinitely. Our current fix is as follows:
I see that you are connecting / disconnecting the client in each thread so it may not be connection related. However, this situation may still happen in your case if the connection breaks right after it was established for some reason (client.connect) or maybe it never worked and then the success call simply blocks producing the reported behavior. A more general solution would surely include to add a timeout to the result.get() fn and improve the disconnect behavior of the mqtt client. |
Hi, thanks for your reply. I've managed to get it running by using paho and making a few changes ( I was missing client.loop_start() ). Now it runs with multiple threads without any issue. I leave it here for anyone trying to do the same: `
` |
I've tested Thingsboard API (HTTP using JMeter) with very good results. Now I've been asked to do the same using MQTT. I’m using the docker image described in https://thingsboard.io/docs/user-guide/install/docker/
For starters, the examples in https://thingsboard.io/docs/reference/python-client-sdk/ do not work with tb-mqtt-client latest versions. By trial and error, I managed to make it work with version 1.1, the only one that worked for sending attributes and telemetry (python -m pip install tb-mqtt-client==1.1).
Using the MQTT python client to create devices never succeeds in provision more than 10.000. It hangs before that without any error.
Since what I was asked to test was sending data (attributes and telemetry) I resorted to pycurl to provision the devices and get their tokens so I could send data to each device.
Following the example in https://github.com/thingsboard/thingsboard-python-client-sdk/blob/master/examples/device/send_telemetry_and_attr.py I created these two functions to send data on custom MQTT class of my own where properties like server address and device token are populated when the device is provisioned using http.
And the main function:
…
…
This code starts by running as expected but after a few hundred attribute writes it gets stuck. Checking the process with ps -u I see that it is waiting in a interruptible sleep (waiting for an event to complete), specifically state “Sl+”.
Any clue as why this works fine for low numbers but gets stuck on a long run? The server is almost idle at 2% CPU usage, lots of free memory and disk.
The text was updated successfully, but these errors were encountered: