Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle mqtt loop_forever function when using Django?

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?

like image 351
mike29892 Avatar asked Oct 30 '14 20:10

mike29892


1 Answers

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.

like image 138
ralight Avatar answered Sep 30 '22 20:09

ralight