Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Support free-threaded Python with a direct-threading backend

Đang mở
#5 1 bình luận 2 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, python
Lĩnh vực
backend

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ả

design

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.c MPSC message queue (already lock-free C11 atomics)
  • _core.c 2PL scheduler and BOCBehavior/BOCCown request machinery
  • behaviors.py Behaviors scheduler thread
  • Cown[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 uses PyMutex or equivalent
  • Behaviors execute closures directly — no transpiler, no AST export, no module re-import
  • _core.c internal state protected with Py_BEGIN_CRITICAL_SECTION where 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

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/bocpy

Tất cả issue của microsoft/bocpy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.