Debugging "The client was disconnected by the server because of inactivity"

Basically, my general principle is that “you” don’t control the Django process. The wsgi container (gunicorn in your case) is in control.
I never recommend starting any kind of thread or process from within Django itself - there are too many ways that things can go wrong because you’re not in charge of the base process.
I don’t see “afirst” as being the issue. I see the root problem as being the launch of a subprocess from within a process you have no control over.
You have no way of knowing when or why gunicorn may decide to restart a worker…

(You can search through the forum here to find multiple cases where I’ve made that point in other circumstances. I just don’t believe it’s a wise idea to try and do it in a production environment.)

1 Like