Skip to content

Commit 521196c

Browse files
committed
Add 2.4.0 changelog and docs for context thread affinity
1 parent 8a7a68c commit 521196c

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## 2.4.0 (Unreleased)
4+
5+
### Added
6+
7+
- **Context thread affinity** - Contexts in MULTI_EXECUTOR mode are now assigned a
8+
fixed executor thread at creation. All operations (call, eval, exec) from the same
9+
context run on the same OS thread, preventing thread state corruption in libraries
10+
like numpy and PyTorch that have thread-local state.
11+
12+
### Changed
13+
14+
- **Removed obsolete subinterp test references** - Test suites updated to reflect
15+
the removal of subinterpreter mode. Tests now use `worker` or `owngil` modes.
16+
317
## 2.3.1 (2026-04-01)
418

519
### Fixed

docs/context-affinity.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ Process-bound environments work by:
357357

358358
For subinterpreters, environments are created inside the target interpreter to ensure memory safety - Python's subinterpreters have isolated memory allocators.
359359

360+
### Thread Safety for C Extensions
361+
362+
Contexts in MULTI_EXECUTOR mode have automatic thread affinity. Each context is
363+
assigned a dedicated executor thread at creation, ensuring that all Python operations
364+
run on the same OS thread. This is critical for C extensions with thread-local state:
365+
366+
- **numpy** - Uses thread-local random state and BLAS threading
367+
- **torch** - Maintains thread-local state for CUDA and CPU operations
368+
- **tensorflow** - Thread-local session state
369+
370+
No configuration is needed - thread affinity is enabled automatically.
371+
360372
## Best Practices
361373

362374
1. **Use explicit contexts for stateful operations**: `Ctx = py:context(1)` ensures state persists

docs/scalability.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ Ctx = py:context(1),
9393

9494
Runs N executor threads that share the GIL. Requests are distributed round-robin across executors. Good for I/O-bound workloads where Python releases the GIL during I/O operations.
9595

96+
**Thread Affinity:** In MULTI_EXECUTOR mode, both workers and contexts are assigned
97+
a fixed executor thread. This ensures libraries with thread-local state (numpy, torch,
98+
tensorflow) always run on the same OS thread, preventing segfaults and state corruption.
99+
96100
## Choosing the Right Mode
97101

98102
### Mode Comparison

0 commit comments

Comments
 (0)