Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ThreadPool execution should preserve contextvar context. #71

@lovelydinosaur

Description

@lovelydinosaur

This is an implementation pattern, rather than something strictly for the ASGI spec.

Something that cropped up while implementing https://github.com/encode/sentry-asgi is that Python's ThreadPoolExecutor does not default to preserving the contextvars context, which really is what you want.

If you're using something like the Sentry SDK, then you needs contextvars in order to properly tie otherwise unrelated events together into, and you need it to continue working properly when threadpools are used.

Here's my fix in Starlette: Kludex/starlette#192

Other ASGI tools and frameworks will want to use something similar when running sync code in threadpools.

Links to core issue here: Kludex/starlette#191

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions