Reputation: 3336
Does Django use processes or threads to handle user requests in view?
If Django uses threads I can't to use all CPU cores(python global interpreter lock), if Django uses processes I can't with no worry share memory.
I tried to find the info in google, but maximum that I have managed to find is Did django use thread to handle requests? This seems isn't a answer.
Upvotes: 17
Views: 9022
Reputation: 53669
Django is run as a WSGI application. How that happens is determined by your WSGI server (e.g. uWSGI, Gunicorn, mod_wsgi).
Django's request handler is thread-safe. You can configure your WSGI server to use any number of processes (sometimes called workers) and threads per process.
As you've mentioned, processes use more memory, but threads are affected by the GIL. A good configuration should find a balance between the number of processes and the number of threads per process.
Upvotes: 18