coverage.tracer thread-safety warning with Python 3.13 free-threaded · Issue #1799 · nedbat/coveragepy (original) (raw)

Is your feature request related to a problem? Please describe.

I am testing Python 3.13 free-threaded in joblib and I get the following warning when running the tests through pytest with the following command-line:

+ PYTEST_ADDOPTS='--cov=joblib --cov-append'
+ pytest joblib -vl --timeout=120 --junitxml=test-data.xml

Warning:

<frozen importlib._bootstrap>:488: RuntimeWarning: The global interpreter lock (GIL) has been enabled to load module 'coverage.tracer', which has not declared that it can run safely without the GIL. To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0 or -Xgil=0.

Describe the solution you'd like

I guess coverage.tracer should declare whether it is safe or not to run without the GIL with free-threaded Python? Not an expert on this but I think the CPython doc may have more details.

Describe alternatives you've considered

I am completely fine setting the environment variable PYTHON_GIL=0. In scikit-learn test suite, this is what we currently do because Numpy also has some C extensions that still haven't declared their free-threaded safety or lack thereof.

Additional context

This is related to a concerted attempt of trying out Python 3.13 free-threaded in the Scientific Python ecosystem, see https://github.com/Quansight-Labs/free-threaded-compatibility for more details.