Free-threaded Python (3.14t/3.15t): importing _objtrace re-enables the GIL
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 39/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend, build-system, documentation, performance, testing
Hướng nghiên cứu
Start with scout_apm/core/objtrace.py and the _objtrace C extension; inspect how the fallback is selected and where the extension declares module slots. Then review .github/workflows/main.yml and the tox environment selection for Python 3.14t and 3.15t. The issue proposes a short term fallback and CI coverage, while making the extension free-threading safe requires investigation and stress tests.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
We publish free-threaded wheels (cp314t and cp315t). For example, scout-apm 4.0.0 on PyPI includes scout_apm-4.0.0-cp314-cp314t-*.whl, and cibuildwheel builds cp315t wheels on master. But nothing in CI tests the free-threaded builds, and the _objtrace C extension never declares that it's safe to run without the GIL. It has no Py_mod_gil slot.
So when scout_apm.core.install() imports scout_apm.core._objtrace on a free-threaded interpreter, CPython turns the GIL back on for the whole process:
RuntimeWarning: The global interpreter lock (GIL) has been enabled to load module 'scout_apm.core._objtrace', 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.
The impact:
- Any free-threaded app with scout-apm installed quietly loses free-threading.
sys._is_gil_enabled()becomesTrueafter the import. - When warnings are errors (
-W error, or our ownpytest.ini), the import raisesRuntimeWarning. The fallback inobjtrace.pyonly catchesImportError, so the exception isn't handled. A free-threaded CI job would fail on this right away.
Reproduce
uv venv -p 3.15t venv && VIRTUAL_ENV=venv uv pip install "scout-apm @ ."
venv/bin/python -c "import sys; from scout_apm.core import objtrace; print(objtrace.is_extension, sys._is_gil_enabled())"
# RuntimeWarning as above, then: True True
What objtrace provides
objtrace only produces the per-span allocation tags: allocations, start_allocations and stop_allocations (tracked_request.py, add_allocation_tags). Memory increase per request (RSS via psutil) and the memory sampler don't depend on it. The agent already runs without objtrace on PyPy, with SCOUT_DISABLE_EXTENSIONS=1, and whenever the optional extension fails to compile. In those cases add_allocation_tags() just skips the tags.
Proposed plan
- Short term: on free-threaded builds, use the existing no-op fallback in
objtrace.pyinstead of importing the extension, for example whensysconfig.get_config_var("Py_GIL_DISABLED")is set. The GIL stays off, and allocation tags are skipped like they are on PyPy. - CI: add
3.14tand3.15tjobs, withpy314t-*andpy315t-*tox envs. The env selection inmain.ymlcurrently strips the version down to digits (3.15tbecomes315) and matches^py315as a prefix, so it would also need to match thetsuffix exactly. - Longer term (needs investigation): make
_objtraceactually safe without the GIL and declarePy_MOD_GIL_NOT_USED. The counters are already thread-local (__thread). The open questions:enable()anddisable()read and writeinstalledwithout a lock. A concurrent doubleenable()would wrap our own hook and recurse infinitely.- We'd need to confirm whether calling
PyMem_SetAllocatorat runtime, while other threads are allocating, is safe on free-threaded CPython. - Stress tests on 3.14t/3.15t would be needed before shipping.
- Docs: say which Python builds and interpreters report allocation counts. Today the docs don't mention objtrace, PyPy or
SCOUT_DISABLE_EXTENSIONSat all.
Found while adding Python 3.15 CI in #866.
- Ngôn ngữ chính
- Python
- Star
- 77
- Fork
- 19
- Merge trung bình
- 4 giờ 6 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của scoutapp/scout_apm_python
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 1/100
scoutapp/scout_apm_python#854 ·
-
redis-py 7.4.0 fixes password leak in ConnectionPool repr and exposes OTel classesCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbotwork
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
scoutapp/scout_apm_python#841 ·
-
Celery 5.6.3 removes deprecated redis get_connection args — verify Scout instrumentationCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbotwork
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
scoutapp/scout_apm_python#837 ·
-
Ensure Elasticsearch 9 compatĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
scoutapp/scout_apm_python#815 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
scoutapp/scout_apm_python#791 ·
Tất cả issue của scoutapp/scout_apm_python
Issue tương tự
-
test-failure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
teramoby/speedle-plus#129 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
btclib-org/btclib-ecc#404 ·
-
verify: just verify runs tools/verify_agents_imports.py (the recipe line was only read, not run)Đang mởneeds-verification
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 76/100
EchoTools/nevr-runtime#1322 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
changelog investigate
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
ramnes/notion-sdk-py#430 ·
-
bug good first issue
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
hyeonjoong/debussy#56 ·