-
Notifications
You must be signed in to change notification settings - Fork 14
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
asyncio functionality is mostly unusable after async handling was applied #93
Comments
A simple solution is to replace
with __loop__ = __asyncio__.new_event_loop()
try:
__async_wrapper_locals__ = __loop__.run_until_complete(__async_wrapper__())
finally:
__loop__.close() For our purpose this is equivalent to We could also have one global event loop instead of recreating it every time for the |
Here is what We could potentially vendor this function and always insert it into the globals of the galleries. That way we can just call __get_asyncio_loop__().run_until_complete(__async_wrapper__()) in our wrapper. |
Reporting on my own failures here. In #90 we added automatic
async
handling and did so by usingasyncio.run
:mkdocs-gallery/src/mkdocs_gallery/gen_single.py
Lines 782 to 783 in 8a16972
The problem is, and I didn't know this before, that
asyncio.run
is meant to be only called once. This is what the documentation says about this:However, we call it for every code block that needs
async
handling. That in itself is not an issue as the gallery here builds just fine. Unfortunately, it breaks down when other libraries that are part of the documentation building also need to use someasync
functionality.For example,
panel
creates anasyncio.Lock
on import. When building someasync
galleries before the import, we effectively have the following situationAnd the
get_event_loop
fails withbecause we have previously used
asyncio.run
.My absolute crude workaround for now is the following snippet that has to be placed before any further
asyncio
functionality is used:Please note that this works for my case, but I have no idea if this screws up other cases as we are messing with low-level private attributes here.
I'll look on how to restructure the async handling to avoid using
asyncio.run
to avoid this mess all together.The text was updated successfully, but these errors were encountered: