python-contextvars

Using a python package in the current app and its child package

Using a python package in the current app and its child package Question: I have a FastAPI app that uses package A as a dependency. On every request to the FastAPI app, package A stores some request string in a ContextVar inside the package. The FastAPI app also uses package B. This package B uses …

Total answers: 1

python contextvars pass and access a variable along the chain of calls

python contextvars pass and access a variable along the chain of calls Question: Context variables are convenient when we need to pass a variable along the chain of calls so that they share the same context, in the case when this cannot be done through a global variable in the case of concurrency. Context variables …

Total answers: 1

Provide contextvars.Context with a ContextManager

Provide contextvars.Context with a ContextManager Question: I’m trying to manage transactions in my DB framework (I use MongoDB with umongo over pymongo). To use transaction, one must pass a session kwarg along the whole call chain. I would like to provide a context manager that would isolate the transaction. Only the function at the end …

Total answers: 1