Skip to content

Commit 310080c

Browse files
timsaucerclaude
andcommitted
docs(distributing): note fork-worker threading.local() inheritance
Forked workers inherit the parent's `threading.local()` slots via copy-on-write until first write, so a child can silently observe a sender or worker context the parent set. Spell that out next to the existing thread-local caveat and tell readers to (re)initialize the slot in the worker rather than rely on inherited state. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent eb762a0 commit 310080c

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

docs/source/user-guide/io/distributing_work.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ Sharp edges:
188188

189189
* Sender and worker slots are **thread-local**. Background threads
190190
on either side see ``None`` until they install their own.
191+
* Under the ``fork`` start method, the parent's ``threading.local()``
192+
values are copied into the child by copy-on-write — a forked
193+
worker initially observes whatever sender / worker slot the parent
194+
had set, until the worker writes its own value (or calls the
195+
matching ``clear_*_ctx``). ``spawn`` and ``forkserver`` workers
196+
start with empty thread-local slots. Treat the slot as
197+
uninitialized on worker entry and install (or clear) it explicitly
198+
in the worker initializer; do not rely on inherited state.
191199
* The global slot persists across ``fork`` workers (copy-on-write
192200
memory inherit) but not across ``spawn`` / ``forkserver`` workers
193201
(fresh process — register or install a worker context on

0 commit comments

Comments
 (0)