threaded Python affected by the GIL

As the GIL is a lock that surrounds the interpreter does it affect compiled Python? I'm wondering whether it is possible to get past the inherent multi-threading limitations of cpython by simply compiling my python before executing it.

Hopefully that makes sense and I'm not missing something obvious or misinterpreting how the GIL works/affects execution.

Thanks


As Daniel said in the comments, it depends on how you "compile" the code.

For example, running the code using Jython does indeed get around the limitations imposed by the GIL.

On the other hand, using something like py2exe makes no difference, since this effectively just packages CPython alongside your code.


Jython does not have a GIL.

IronPython does not have a GIL.

You can compile your python code with cython, and then whether it uses the GIL or not depends. If you convert all you python variables into cython types, you can run your code in a with nogil block and you will have no GIL because you are expressly releasing the GIL. If you are not running in a nogil block, you will be affected by cpython's GIL. More in the cython docs: http://docs.cython.org/src/userguide/external_C_code.html#acquiring-and-releasing-the-gil

For more on python and the GIL, read up here: http://www.jeffknupp.com/blog/2013/06/30/pythons-hardest-problem-revisited/

链接地址: http://www.djcxy.com/p/86470.html

上一篇: 捕获过程输出时产生性能

下一篇: 受GIL影响的线程化Python