Answer the question
In order to leave comments, you need to log in
When to use multiprocessing/multithreading/asyncio?
Good afternoon. I just can’t understand: in what cases is it worth and more profitable to use multiprocessing / multithreading / asyncio and what are their pros and cons? And how do processes and threads bypass the GIL?
Answer the question
In order to leave comments, you need to log in
Not a pythonist, but I'll try to answer. The GIL itself lives inside a process, so creating multiple copies of a single process is entirely possible. GIL of different processes will not overlap in any way. Different processes can process different data. Different processes do not have shared memory (if we do not take into account shared-memory ). Different processes can do a lot of useful things - parse files, process user requests, and so on.
Streams are different. So all threads belong to the same process, and they have a common GIL memory that cannot be bypassed. But there is a nuance. If a thread performs a certain system function that is generally not related to the python itself, then any number of such functions can be performed simultaneously. The main examples of such functions are reading and writing data to files (or sockets). That is, you can receive many messages at once in different threads, but as soon as we fall out into the python, the GIL code will again take effect and begin to execute them in turn.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question