Do cover letters from PEP-492 bypass the GIL in Python 3.5?

Python 3.5 includes shared support since PEP-492 ; which is big and that's it .... assuming coroutines go around the GIL ; does anyone know if this is the case? Or should I keep using the module multiprocessing

?

+3


source to share


1 answer


I would say that coroutines do not bypass the GIL.

The reason is that coroutines are never processed in parallel. Coroutines is a language function that does some pseudo-parallel processing without actually executing a real parallel task, thread or anything else. Only one coroutine is executed at a time.

Remember: even when using a coroutine, you can still have different threads in your program!

Thus, the GIL is not affected because the GIL is just a means of preventing actual thread concurrency in certain parts of the Python interpreter, which could lead to global data corruption.

When you use a threaded version of Python, you have a GIL - and a thread, and no GIL traversal coroutine. But coroutines do not affect the GIL, because threads, because threads can be stopped by the GIL, when entering critical sections. There are no coroutines unless the second thread is running ... (but this is a streaming issue in your program, not a coroutine).



Of course, you can (at least it was possible a while ago) create a threadless version of the Python interpreter (when you really don't need it) by compiling the interpreter yourself. In this version, the GIL should not be executed.

But you have to make sure that no module you are using uses threads, as this module will break.

Edit: After reading your question a second time, I think you really want to ask if the GIL overhead (applicable in threads) is lower in the coroutine.

I would say yes. Even when the GIL is active in your version of the interpreter. Because by limiting its execution to collaborative multiprocessing, the GIL will not (or less when you still have multiple threads) affect your coroutines, as it does when you have multiple worker threads. There will be less (or no) controversy over GIL reservations.

There is also the Tornado web server that has been using coprocessor processing technologies for a longer time in Python, very successfully. This should show that co-processing is the definitively good choice when using Python. There are also other examples of programs that are fast using coprocessor processing technology (eg Nginx).

+1


source







All Articles