How to handle mqtt loop_forever function when using Django?

I am working on a website and am using Django for development. I have several devices that communicate with the site using MQTT, and I plan to use the paho-mqtt client. My problem is that for the paho-mqtt function, I have to call a function that loops forever while paho-mqtt continues to listen to messages. What is the best way for this loop to call and contain its own thread?

Is it possible to create a new thread or use something like celery?

+5
source share
1 answer

Use the threaded interface for paho-mqtt instead. This starts a background thread to handle network processing and can be accessed using loop_start() . Alternatively, you can create your own thread and just call loop() yourself.

+3
source

Source: https://habr.com/ru/post/1205894/


All Articles