Skip to content

Preserve context vars for sync tasks #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

slafs
Copy link

@slafs slafs commented Jul 9, 2025

Fixes #482

Run sync tasks within copied context.

This is heavily inspired by starlette's run_in_threadpool function
introduced in encode/starlette#192.

Nowadays, starlette is just using anyio.to_thread.run_sync, which does a bunch of extra stuff too,
but from my (limited) understanding,
introducing that would require some changes to the architecture of the project itself 🤔. IDK.

slafs added 2 commits July 9, 2025 17:34
The one for sync fails ATM.
For async is OK.
Run sync tasks within copied context.

This is heavily inspired by starlette's `run_in_threadpool` function
introduced in encode/starlette#192.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync tasks loose contextvars
1 participant