MCPcopy
hub / github.com/dask/dask / ContextAwareThreadPoolExecutor

Class ContextAwareThreadPoolExecutor

dask/threaded.py:39–59  ·  view source on GitHub ↗

Variant ThreadPoolExecutor that propagates contextvars from the submitting thread to the worker threads. With a vanilla ThreadPoolExecutor, contextvars are automatically propagated on CPython 3.14t (noGIL) if and only if they are set before the worker threads are started. This v

Source from the content-addressed store, hash-verified

37
38
39class ContextAwareThreadPoolExecutor(ThreadPoolExecutor):
40 """Variant ThreadPoolExecutor that propagates contextvars
41 from the submitting thread to the worker threads.
42
43 With a vanilla ThreadPoolExecutor, contextvars are automatically propagated on
44 CPython 3.14t (noGIL) if and only if they are set before the worker threads are
45 started.
46 This variant propagates contextvars on all Python interpreters and also when the
47 worker threads are already warm when the variables are set in the submitting thread.
48
49 This also affects catching warnings, which on 3.14t use contextvars.
50
51 See Also
52 --------
53 https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_THREAD_INHERIT_CONTEXT
54 https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_CONTEXT_AWARE_WARNINGS
55 """
56
57 def submit(self, fn, /, *args, **kwargs):
58 ctx = contextvars.copy_context()
59 return super().submit(ctx.run, fn, *args, **kwargs)
60
61
62def get(

Callers 1

getFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…