Shifting from multi-threading to multiprocessing

how to make Django uses multiprocessing instesd multi-threading in handling requests to take advantage of multiple CPU cores?

One option is to use gunicorn. Note that the runserver is not intended to be used in production.

Is it a better idea to use multiprocessing?

I don’t understand the intent of what you are asking here. Perhaps you can re-ask your question?

gunicorn will take care of starting your django application with multiple processes to handle requests in parallel.

I mean what are the disadvantages of using multiprocessing? is multiprocessing better than multi-threading in handling requests? and if it is why didn’t the development team of Django make it the default architecture?

I am pleasured for your replies :grin:

These are questions that go far beyond being Django-related. There are advantages and disadvantages of each, and a full discussion of which would take far more space than what can be done in a forum post.

That’s actually not something that can be determined within Django itself. Django doesn’t control its runtime environment.

Keep in mind that the runserver development tool is something created to help you debug code while you’re developing it. DO NOT USE runserver AS YOUR PRODUCTION SERVER. Also, do not draw conclusions about “Django-in-production” from any behavior produced by runserver.

This question came to mind just because I thought that multi-threading in python doesn’t actually increase the performance since python uses GIL to protect reference counting from race conditions.

It does acually, check this out GitHub - colesbury/nogil: Multithreaded Python without the GIL
it works python3.9 without GIL, and soon python 3.13 without GIL officialy PEP 703 – Making the Global Interpreter Lock Optional in CPython |