tomwojcik/starlette-context

Access content in thread

oschulzSam opened this issue · 2 comments

Hi, thank you for this project.

I use the application context to log authorization data. It works fine, until an application start a thread. Is it possible to use the context in threads, started while a request?

Thank you.

Hey, thanks!

ContextVar, which I'm using to store the context, works with the current event loop and event loop works in a thread. If you start a new thread, I don't think it's possible to pass context (actually ContextVar) as well.

What you can do is pass the data from the context and then use this data in your new thread but any change from this new thread won't be propagated to the context object.

Thank you very much!