A ThreadPoolExecutor that automatically copies the caller's ``contextvars.Context`` into each worker invocation. This ensures Sentry SDK scopes (isolation_scope, current_scope), OpenTelemetry trace context, and any other context variables are available in worker threads without manu
| 241 | |
| 242 | |
| 243 | class ContextPropagatingThreadPoolExecutor(_ThreadPoolExecutor): |
| 244 | """A ThreadPoolExecutor that automatically copies the caller's |
| 245 | ``contextvars.Context`` into each worker invocation. |
| 246 | |
| 247 | This ensures Sentry SDK scopes (isolation_scope, current_scope), |
| 248 | OpenTelemetry trace context, and any other context variables are |
| 249 | available in worker threads without manual propagation. |
| 250 | """ |
| 251 | |
| 252 | def submit(self, fn, /, *args, **kwargs): |
| 253 | ctx = contextvars.copy_context() |
| 254 | return super().submit(ctx.run, fn, *args, **kwargs) |
| 255 | |
| 256 | |
| 257 | class FutureSet: |
no outgoing calls