【问题标题】:Is there a general purpose way to test for the existence of a GIL?是否有通用方法来测试 GIL 的存在?
【发布时间】:2013-09-12 22:34:52
【问题描述】:

我正在编写一个多线程 Python 应用程序,它在系统上的行为会有所不同,具体取决于 GIL 实现的细节。

我是否有一种通用的方法来测试我正在运行的解释器是否具有 CPython 风格的 GIL?

【问题讨论】:

    标签: python cpython gil


    【解决方案1】:

    不,stdlib 没有 API 或标志来测试 GIL。现在您可以放心地假设所有版本的 CPython 和 PyPy 都有 GIL,而 IronPython 和 Jython 没有 GIL。

    Python 3.3 和更新版本有sys.implementation.name。在旧版本中,您可以使用platform.python_implementation()。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-20
      • 1970-01-01
      • 2011-12-30
      • 2011-05-14
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      相关资源
      最近更新 更多