I am using Django 4.0.1 with the channels extension, so I'm using the ASGI interface.
In one of my applications, I'm using it's AppConfig.ready() method to start a thread / asnyc loop - specifically the paho.mqtt package via loop_start(). If a message arrives on a subscribed topic, this application handles some business logic.
This works fine for my usecase - with the exception of two problems:
- It's also started when I use any
manage.py
command. ./manage.py runserver
(with reload enabled) will spawn a second process, which results in two connections being made - and I only need one.
While I could use a filesystem-mutex to block the execution of a second application, I'd like to know, if there's a more "Django way" of solving this?