Created
April 8, 2024 08:58
-
-
Save GreyElaina/d09a6671127a167c771205c74d3d36e0 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
| from contextvars import ContextVar, Context | |
| import gc | |
| def get_current_context(): | |
| local = ContextVar("#local") | |
| token = local.set(1) | |
| for i in gc.get_referents(token): | |
| if isinstance(i, Context): | |
| return i | |
| raise RuntimeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment