establish a global context object
context_stack_trace is a contextmanager that is used to track usage of other context managers (such as request_context_safety). It pushes a manager_id onto a thread local stack in its entering block and pops it on exit.
@contextmanager def my_manager():
- with context_stack_trace(‘my_manager’):
- # do entering yield # do exiting
This way you can check which context managers are active at the moment.
To prevent accidental nesting of managers with the same id, you can set the parameter allow_nesting to False
returns, if we are inside a traced context manager with id manager_id. can be used to set access rights on some thread local variables, e.g. LocalContainer instances.
request_context_safety is a context managers that wraps the usage of request_context. to avoid data leakage through thread recycling we have to remove thread local data from request_context when the thread exits. the request_context_safety manager does that for you.
linotp enforces this manager, so using request_context outside of request_context_safety will raise an exception.
- with request_context_safety():
- # we can use request_context now, e.g.: request_context[‘config’] = getLinotpConfig # ...