temporalio / temporalio/samples-python

[Question] Had some queries around the context propagation example

Open
#176 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
367
Forks
121
Avg merge
3d 20h
Merged PRs (30d)
11

Description

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?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with context_propagation/README.md and review the linked Temporal Python SDK issue #263. Determine whether ContextVar.reset() changes behavior for thread-pool activities and concurrent workflows, then document the supported guidance and any conditions where resetting matters.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.