You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This function should be used as a main entry point for asyncio programs, and should ideally only be called once.
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 some async functionality.
For example, panel creates an asyncio.Lock on import. When building some async galleries before the import, we effectively have the following situation
For our purpose this is equivalent to asyncio.run, but doesn't set the _set_called flag that prevents more event loops from being created.
We could also have one global event loop instead of recreating it every time for the async handling. I'll have a look at how difficult it would be to fit in.
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: