Skip to content

Instantly share code, notes, and snippets.

@pfreixes
Created February 17, 2018 15:12
Show Gist options
  • Save pfreixes/cb6447ee8cfd64becac0f101694c84eb to your computer and use it in GitHub Desktop.
Save pfreixes/cb6447ee8cfd64becac0f101694c84eb to your computer and use it in GitHub Desktop.
Python 3.7.0b1 (v3.7.0b1:9561d7f501, Jan 30 2018, 19:10:11)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import contextvars
>>> foo = contextvars.ContextVar("foo")
>>> foo.set("a")
<Token var=<ContextVar name='foo' at 0x10ccbe2b0> at 0x10ccc36c0>
>>> bar = contextvars.ContextVar("bar", default="b")
>>> list(contextvars.copy_context().keys())
[<ContextVar name='foo' at 0x10ccbe2b0>]
@pfreixes
Copy link
Author

>>> def test():
...   print(bar.get())
...
>>> contextvars.copy_context().run(test)
b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment