microsoft/bocpy v0.5.0
microsoft/bocpy
Captured source
source ↗published May 5, 2026seen 4dcaptured 13hhttp 200method plain
v0.5.0
Repository: microsoft/bocpy
Tag: v0.5.0
Published: 2026-05-05T10:28:05Z
Prerelease: no
Release notes:
Highlights
This release delivers a Verona-RT-style work-stealing scheduler, a global noticeboard (shared key-value store), removal of the central scheduler thread in favour of direct dispatch, and a major C source refactor into per-subsystem translation units with a portable atomics layer.
---
New Features
- Work-stealing scheduler — the single behavior queue is replaced with a distributed scheduler. Each worker owns an MPMC behavior queue, pops locally first, and steals from peers when idle. Idle workers park on per-worker condition variables and are signalled directly by producer/victim.
- Per-worker fairness tokens — a token node advances through each worker's queue so long-running behaviors cannot monopolise dispatch slots; also drives cooperative shutdown.
- Noticeboard — a shared key-value store (up to 64 keys) readable/writable without acquiring cowns. Writes are non-blocking; reads return a cached per-behavior snapshot. Includes
notice_write,notice_read,notice_update,notice_delete,notice_sync,noticeboard_version, and theREMOVEDsentinel. - Distributed scheduler — two-phase locking, request linking, and dispatch run directly on the caller's thread in C; cown release runs on the executing worker. MCS-style intrusive linked list per cown for zero-bounce handoff.
- `Cown.exception` property — indicates whether the held value is from an unhandled exception.
- `compat.h` / `compat.c` portability layer — uniform
BOCMutex,BOCCond,boc_atomic_*_explicit, monotonic-time, and sleep primitives across MSVC, pthreads, and C11 ``. - `xidata.h` cross-interpreter shim — centralised
_PyXIData_*/_PyCrossInterpreterData_*version ladders for CPython 3.12–3.15 (including free-threaded builds). - `fanout_benchmark` example — fan-out/fan-in benchmark exercising scheduler throughput under heavy producer load.
- Prime factor example (
examples/prime_factor.py) — parallel factorisation via Pollard's rho with noticeboard-coordinated early termination. - Benchmark harness (
examples/benchmark.py) — micro-benchmarks for scheduling throughput, message-queue latency, and noticeboard contention.
Bug Fixes
- Transpiler aliased imports —
visit_Import/visit_ImportFromnow track alias names (import X as Y), preventing spurious "name not found" errors and duplicatewhencallinjection. - Global variable capture —
@whenclosure capture falls back toframe.f_globalswhen a name is not in any local scope, fixingNameErrorfor module-level variables.
Improvements
- In-memory transpiled-module loading — workers
execthe transpiled source from a string literal instead of writing to disk, eliminating filesystem round-trips and leftover.pyfiles. - Nested `@when` capture — the transpiler recurses into nested
@when-decorated functions when computing outer captures, so child behaviors can close over the outer frame. - C extension split —
_core.creduced from ~5,000 to ~3,500 lines by extractingsched.{c,h},noticeboard.{c,h},terminator.{c,h},tags.{c,h},cown.h,compat.{c,h}, andxidata.h. - Direct dispatch on cown release —
behavior_release_allhands resolved successors directly to workers viaboc_sched_dispatch, removing one queue hop per handoff. - Cooperative worker shutdown —
boc_sched_worker_request_stop_all/boc_sched_unpause_allprovide a clean stop/drain protocol. - Matrix docstrings — all
MatrixC methods now carry built-in docstrings. - Examples package relocated — moved to top-level
examples/directory (still importable asbocpy.examples). - Filtered PyPI README —
setup.pystrips `` regions before publishing. - Documentation refresh — expanded coverage of noticeboard, distributed scheduler, and new APIs.
Internal Test Modules (opt-in via BOCPY_BUILD_INTERNAL_TESTS=1)
_internal_test_atomics— correctness tests forcompat.htyped-atomics._internal_test_bq— torture tests for the MPMC behavior queue._internal_test_wsq— tests for work-stealing primitives (fast pop, slow pop, steal, park/unpark).
Test Suite
test_noticeboard.py— snapshot semantics,notice_updateatomicity,REMOVED,notice_sync, version monotonicity.test_scheduler_integration.py,test_scheduler_stats.py,test_scheduler_steal.py— end-to-end and per-primitive scheduler tests.test_compat_atomics.py— portable atomics smoke tests.test_stop_retry_composition.py—stop()/start()/wait()retry composition.test_scheduling_stress.py— expanded with fan-out, work-stealing, and shutdown stress scenarios.test_transpiler.py— AST extraction, capture rewriting, aliased imports, module export.
---
Full changelog: v0.3.1...v0.5.0
Notability
notability 3.0/10Minor library version update.