samples-python icon indicating copy to clipboard operation
samples-python copied to clipboard

[Question] Had some queries around the context propagation example

Open Daanial11 opened this issue 9 months ago • 1 comments

Hi, was just implementing a context propagation interceptor based on this sample: https://github.com/temporalio/samples-python/blob/main/context_propagation/README.md

After a bit of experimentation, it seems like the the contextvar value is automatically restored to the previous value during multiple concurrent workflow runs and even after an activity finishes executing (if the var was updated inside the activity).

I was wondering if the ContextVar.reset() usage in the sample is redundant? or are there scenarios where it might have an effect?

I'm using a thread pool executor for my worker, so perhaps thats why it seems like ContextVar.reset() does not do anything? https://github.com/temporalio/sdk-python/issues/263

Would it be safe to remove the resetting part when using a thread pool executor for activity tasks? And for workflows in general if I don't want the context vars state to leak between them?

Daanial11 avatar Apr 11 '25 16:04 Daanial11