>>> with ThreadedContext(knights='ni', eki='patang'):
>>> print(get_current_context())
>>> with ThreadedContext(knights='round table', color='red'):
>>> print(get_current_context())
>>> print(get_current_context())
>>> print(get_current_context())
... {'eki': 'patang', 'knights': 'ni'}
... {'eki': 'patang', 'color': 'red', 'knights': 'ni'}
... {'eki': 'patang', 'knights': 'ni'}
... {}
# A weak context will be overrided by values declared in other context inside it.
>>> with WeakThreadedContext(knights='ni', eki='patang'):
>>> print(get_current_context())
>>> with ThreadedContext(knights='round table', color='red'):
>>> print(get_current_context())
>>> print(get_current_context())
>>> print(get_current_context())
... {'eki': 'patang', 'knights': 'ni'}
... {'eki': 'patang', 'color': 'red', 'knights': 'round table'}
... {'eki': 'patang', 'knights': 'ni'}
... {}
# Even if the context inside is also weak. The last weak or the first strong will prevail.
>>> with WeakThreadedContext(knights='ni', eki='patang'):
>>> print(get_current_context())
>>> with WeakThreadedContext(knights='round table', color='red'):
>>> print(get_current_context())
>>> print(get_current_context())
>>> print(get_current_context())
... {'eki': 'patang', 'knights': 'ni'}
... {'eki': 'patang', 'color': 'red', 'knights': 'round table'}
... {'eki': 'patang', 'knights': 'ni'}
... {}
-
Notifications
You must be signed in to change notification settings - Fork 0
Very simple context tracking decorator / context handler.
License
dolead/threaded-context
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Very simple context tracking decorator / context handler.