Do coroutines from PEP-492 bypass the GIL in Python 3.5? -
python 3.5 includes co-routine support pep-492; great , all.... assuming coroutines go around gil; know if that's case? or, should keep using multiprocessing
module?
i say, coroutines not bypass gil.
the reason is, coroutines never processed in parallel. coroutines language feature kind of pseudo-parallel processing without real parallel task, thread or else execution. 1 coroutine ever executed @ once.
remember: even, when using coroutines, can still have different threads in program!
so, gil not affected, because gil means prevent real parallel processing of threads in specific parts of python interpreter, end in corruption of global data.
when using thread-enabled version of python, have gil -- , no thread , no coroutines "bypass" gil. coroutines not affected gil, threads are, since threads stopped gil, when entering critical sections. coroutines not, unless second thread running ... (but problem of threading in program, not of coroutines).
of course, can (at least possible time ago) create python interpreter version no thread-support (when don't need it), compiling interpreter yourself. in such version, gil should not executed.
but must sure, no module using, using threading, since module break.
edit: after reading question second time, guess, want ask is, if gil-overhead (applicable in threads) lower in coroutines.
i say, yes. when gil active in version of interpreter. because limiting execution cooperative multiprocessing, gil not (or less, when still have more 1 thread) affect coroutines, when have multiple worker threads. there less (or no) contention on reserving gil.
there webserver "tornado" uses coprocessing technologies longer time in python, successfully. should show, coprocessing definitively choice, when using python. there other examples of programs fast using coprocessing technology (e.g. nginx).
Comments
Post a Comment