Skip to content

Very simple context tracking decorator / context handler.

License

Notifications You must be signed in to change notification settings

dolead/threaded-context

Repository files navigation

Build Status Code Climate Coverage Status

>>> 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'}
... {}

About

Very simple context tracking decorator / context handler.

Topics

Resources

License

Stars

Watchers

Forks

Languages