When I run uwsgi with a single process, it works fine. But when I run uwsgi with several processes on the different sockets [8001-8008], the whole app works fine except the Dash graphs. I get the following error:
Unable to find stateless DjangoApp called app
Any guesses of how can I solve this in order to run Dash with multiprocessing with NGINX+UWSGI+Django?
Yes, the Dash graphs are part of a greater project. The endpoint used for the Dash app is as follows:
views.py
@api_view(['GET'])
def chart_genome(request):
# Fill kwargs with the info from the request to tell which case should be plotted and some info such as the language
generate_plot(**kwargs)
return render(request, 'plots/genome.html')
So your problem is that generate_plot is not always called, so in some processes there is no Genome dash instance. If you invoke it at the bottom of genome.py, so it is called on every import (and thus in every process when Django imports all of the urls), your multiprocess error should be resolved.
If you need different kwargs content when calling this function then you’ll need to use stateful, not stateful, Dash instances.
Hi, thanks a lot for the answer, it was really helpful.
The thing is that the frontend calls to this endpoint providing the parameter of the case that should be plotted, for instance:
User A: /api/genome?ID_CASE=1234
User B: /api/genome?ID_CASE=5678
If I call generate_plot on every instance passing as kwargs param ID_CASE=1234, every one of them will have an instance of this graph, so the cases will get missed among the different users, no? User B will get the case of user A, right? If so, is there any way to fix this? Because the thing is that I do not know how to make the ID_CASE param also visible for the internal dash calls such as update_layout, which I do not know if it would be neccesary.
On the other hand, I am wondering: I did this this way because I needed to pass the param ID_CASE from the Django view to the Dash graph. Is it possible to have a stateless app where you could pass them this input param that is unique for each user?
So you’re saying that the app has internal state; for this you can use a stateful DashApp instance.
You will need to think about how you share/obtain the data; I’d go for an approach where the app contains the ID_CASE reference and then access the data associated with it in the callbacks, probably leveraging Django’s caching if getting this data is expensive.