3

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?

blueberryfields
  • 45,910
  • 28
  • 89
  • 168

1 Answers1

1

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'
Christian Heimes
  • 1,365
  • 10
  • 10