Is there a general purpose way to test for the existence of a GIL?

90 Views Asked by At

I'm writing a multi-threaded Python application, which will behave differently on systems, depending on the details of the GIL implementation.

Is there a general purpose way for me to test whether the intepreter I'm running on has a CPython style GIL?

1

There are 1 best solutions below

0
On

No, the stdlib has no API or flag to test for the GIL. For now you can safely assume that all versions of CPython and PyPy have a GIL while IronPython and Jython don't have a GIL.

Python 3.3 and newer have sys.implementation.name. In older versions you can use platform.python_implementation().

>>> import sys
>>> sys.implementation.name
'cpython'
>>> import platform
>>> platform.python_implementation()
'CPython'