Currently my init.py looks like this:
from . import mqtt
mqtt.client.loop_start()
But when I run it some actions in the loop are done more than once. When I place a time.sleep(30) in front everything works as intended. But I think this is not the best thing to do.
How do I run my loop only when everything else has loaded.
I tried putting it in an AppConfig ready like so:
from django.apps import AppConfig
from . import mqtt
class PrintConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'print'
def ready(self):
mqtt.client.loop_start()
but I get the following error:
RuntimeError("populate() isn't reentrant")
Is there something I need to add to my INSTALLED APPS when I use the def ready(self): function ?