Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run_sync (v3) raises AsyncLibraryNotFoundError for python3.6 #286

Closed
mwakaba2 opened this issue May 9, 2021 · 5 comments · Fixed by #288
Closed

Run_sync (v3) raises AsyncLibraryNotFoundError for python3.6 #286

mwakaba2 opened this issue May 9, 2021 · 5 comments · Fixed by #288
Labels
asyncio Involves the asyncio backend bug Something isn't working

Comments

@mwakaba2
Copy link

mwakaba2 commented May 9, 2021

Problem

The AsyncLibraryNotFoundError is getting raised for running a synchronous function in a worker thread in py3.6.

For more context, Jupyter Server #505

How to reproduce

Python version: Python 3.6.13 :: Anaconda, Inc.

Confirm AsyncLibraryNotFoundError isn't raised for anyio==2.2.0.

$ pip install anyio==2.2.0
$ python test_run_sync.py

AsyncLibraryNotFoundError shows up for anyio==3.0.1 in python3.6. I ran this in python3.7, and the error didn't show up.

$ pip install anyio==3.0.1
$ python test_run_sync.py

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

The test_run_sync.py script: https://gist.github.com/mwakaba2/e76b0bc341bf17c97ff58cd4c672e4d4

@agronholm
Copy link
Owner

Thanks, the repro script should speed up the investigation a lot!

@agronholm agronholm added asyncio Involves the asyncio backend bug Something isn't working labels May 10, 2021
@agronholm
Copy link
Owner

For some reason, I cannot reproduce this in the test suite, even if I run the exact same code without any fixtures, and only that test.

@agronholm
Copy link
Owner

I have an elegant fix for this but without a working regression test I'm hesitant to commit it.

@mwakaba2
Copy link
Author

@agronholm Thanks so much for the quick fix!

In your PR, I see a test that checks for any exceptions in run_sync. Were you able to reproduce the exception before the fix?

@agronholm
Copy link
Owner

Yes, the test fails without the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asyncio Involves the asyncio backend bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants