I am working on a website and am using Django for development. I have a few devices that communicate to the website using MQTT, and I plan to use paho-mqtt client. My issue is that for paho-mqtt to function I must call a function that loops forever while paho-mqtt continues to listen for messages. What is the best way to have this loop called and contained in it's own thread?
Can I just create a new thread, or should I use something like celery?
Use the threaded interface to paho-mqtt instead. This starts a background thread to handle the network processing and can be accessed with loop_start()
. Alternatively you could make your own thread and just call loop()
yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With