Support free-threaded Python with a direct-threading backend
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Trước tiên, hãy đọc _core.c và behaviors.py, tập trung vào scheduler hiện có, hàng đợi thông báo và cơ chế yêu cầu của BOCBehavior/BOCCown. Xác nhận cách phát hiện mô hình threading của runtime và cách các đường dẫn hiện tại của subinterpreter, XIData và BOCRecycleQueue được kết nối. Công việc được xem là hoàn tất khi một backend free-threaded ổn định có thể sử dụng các thread trực tiếp mà vẫn duy trì các đảm bảo của BOC về việc không xảy ra deadlock và data race.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Python 3.13+ ships an optional free-threaded build (--disable-gil) where the GIL is removed entirely. In free-threaded Python, plain threads already run in parallel — subinterpreters are no longer needed for parallelism, only isolation. bocpy should offer an optimized execution path for this runtime that avoids subinterpreter and XIData overhead while preserving BOC's deadlock-freedom guarantees.
This work is gated on the free-threaded ecosystem stabilizing. The free-threaded build is still experimental as of Python 3.15 and the subinterpreter/XIData APIs continue to evolve. We should not invest in a second backend until the APIs are stable and the free-threaded build is no longer opt-in.
Motivation
On free-threaded Python, bocpy's current architecture pays significant overhead for no parallelism benefit:
- XIData serialization/deserialization on every cown transfer (pickle round-trip for complex types)
- Subinterpreter lifecycle management (create, run_string, destroy per worker)
- Transpiler/AST export step to make closures importable across interpreters
- Module re-import in each worker interpreter
All of this machinery exists to work around the per-interpreter GIL. Without a GIL, workers can be plain threads operating directly on shared Python objects, and the cown/2PL protocol itself provides the necessary thread safety.
BOC's value proposition — deadlock and data-race freedom by construction — is arguably more valuable on free-threaded Python, where programmers face genuine shared-memory concurrency hazards that the GIL previously masked.
Design
At runtime, detect the threading model and select the appropriate backend:
import sys
if hasattr(sys, '_is_gil_enabled') and not sys._is_gil_enabled():
# Free-threaded: use direct threading
else:
# GIL build: use subinterpreters (current path)
Shared components (unchanged in either mode):
_core.cMPSC message queue (already lock-free C11 atomics)_core.c2PL scheduler andBOCBehavior/BOCCownrequest machinerybehaviors.pyBehaviorsscheduler threadCown[T]public API
Free-threaded mode changes:
- Workers become plain
threading.Threads running in the main interpreter - Cowns store
PyObject*directly instead of going through XIData — acquire/release usesPyMutexor equivalent - Behaviors execute closures directly — no transpiler, no AST export, no module re-import
_core.cinternal state protected withPy_BEGIN_CRITICAL_SECTIONwhere dicts/lists are accessed concurrently- The
BOCRecycleQueue(XIData GC) becomes unnecessary
- Ngôn ngữ chính
- Python
- Star
- 198
- Fork
- 9
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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 microsoft/bocpy
-
Cowns missed opportunityĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 63/100
-
design
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
design
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
-
maths
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Tất cả issue của microsoft/bocpy
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Graphify-Labs/graphify#4241 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
DeviceTrackerĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
XiaoMi/ha_xiaomi_home#1821 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Maven path-index: "Ambiguous or noncanonical artifact path" error does not report the offending pathĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
pulp/pulp_maven#524 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày