This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: contextvars does not work properly in asyncio REPL.
Type: behavior Stage: patch review
Components: asyncio Versions: Python 3.9, Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, lanfon72, yselivanov
Priority: normal Keywords: patch

Created on 2021-03-06 14:09 by lanfon72, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 24773 open lanfon72, 2021-03-06 15:06
Messages (1)
msg388199 - (view) Author: Lanfon (lanfon72) * Date: 2021-03-06 14:09
Demonstration (via python -m asyncio):

asyncio REPL 3.9.0 (default, Oct 18 2020, 00:21:26) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from contextvars import ContextVar
>>> ctx = ContextVar('ctx')
>>> ctx.set(1)
<Token var=<ContextVar name='ctx' at 0x1021bbc70> at 0x1021bf800>
>>> ctx.get()
Traceback (most recent call last):
  File "/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py", line 440, in result
    return self.__get_result()
  File "/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/asyncio/__main__.py", line 34, in callback
    coro = func()
  File "<console>", line 1, in <module>
LookupError: <ContextVar name='ctx' at 0x1021bbc70>
>>> exit()


It also got problem inside the functions when the context is referenced in global scope.
History
Date User Action Args
2022-04-11 14:59:42adminsetgithub: 87585
2021-03-06 15:06:01lanfon72setkeywords: + patch
stage: patch review
pull_requests: + pull_request23541
2021-03-06 14:09:53lanfon72create