jupyter_server: Anyio version v3 breaks AsyncContentsManager for python3.6

Description

AsyncFileContentsManager tests are timing out in a python 3.6 environment due to a AsyncLibraryNotFoundError error.

DEBUG    ServerApp:log.py:54 200 GET /a%40b/api/contents/foo/a.txt?content=1 (127.0.0.1) 2.04ms
ERROR    asyncio:base_events.py:1296 Exception in callback WorkerThread.stop(<Task finishe...> result=None>)
handle: <Handle WorkerThread.stop(<Task finishe...> result=None>)>
Traceback (most recent call last):
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/anyio/_backends/_asyncio.py", line 708, in stop
    _threadpool_workers.get().discard(self)
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/anyio/lowlevel.py", line 113, in get
    return self._current_vars[self._name]
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/anyio/lowlevel.py", line 97, in _current_vars
    token = current_token()
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/anyio/lowlevel.py", line 54, in current_token
    return get_asynclib().current_token()
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/anyio/_core/_eventloop.py", line 109, in get_asynclib
    asynclib_name = sniffio.current_async_library()
  File "/Users/mwaka/opt/anaconda3/envs/jp_test_3.6/lib/python3.6/site-packages/sniffio/_impl.py", line 82, in current_async_library
    "unknown async library, or not in async context"
sniffio._impl.AsyncLibraryNotFoundError: unknown async library, or not in async context

Reproduce

$ pytest -vv jupyter_server/tests/services/contents/test_api.py

Expected behavior

The tests should pass in ~10 seconds.

pytest -vv jupyter_server/tests/services/contents/test_api.py  6.81s user 2.50s system 89% cpu 10.358 total

Context

  • Operating System and version: MacOS, 10.15.7 (Catalina)
  • Python version: Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

AnyIO relies on sniffio to detect the current async library. It cannot function without this detection. The only difference between py3.6 and 3.7 that would matter here is the support for context variables. This looks like it happens in the callback where the asyncio thread pool is being shut down. I will try to figure this out.

Still working out PR agronholm/anyio#289. After that’s dealt with I will make a release.

v3.1.0 is out now.

I have a couple more PRs to go through and then I’ll make the v3.1.0 release. ETA 1-3 days.