Last active
October 5, 2017 23:47
-
-
Save palazzem/6cd522c8c9724919397b5f8f11fff0c6 to your computer and use it in GitHub Desktop.
pygotham_context_propagator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
def set_current_context(ctx, loop=None): | |
# retrieves the current Task | |
loop = loop or asyncio.get_event_loop() | |
task = asyncio.Task.current_task(loop=loop) | |
# attach the Context to the task! | |
setattr(task, '__current_ctx', ctx) | |
def get_current_context(loop=None): | |
# retrieves the current Task | |
loop = loop or asyncio.get_event_loop() | |
task = asyncio.Task.current_task(loop=loop) | |
# get the Context | |
ctx = getattr(task, '__current_ctx', None) | |
return ctx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment