Last active
August 5, 2021 22:05
-
-
Save adriangb/b5f453eec66c5c6694364cb8e5891af3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import contextvars | |
ctxvar = contextvars.ContextVar("ctx") | |
async def lifespan(): | |
ctxvar.set("spam") | |
return contextvars.copy_context() | |
async def endpoint(): | |
assert ctxvar.get() == "spam" | |
async def main(): | |
ctx = await asyncio.create_task(lifespan()) | |
await asyncio.create_task(ctx.run(endpoint)) # doesn't work, just an example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment