Fix asyncio
in AsyncLLM
to use the running event loop if any
#501
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a hot-fix for the
AsyncLLM
class and subclasses, since theevent_loop
is always created, but in Colab there's already an active running event loop, so that should be reused, otherwise theAsyncLLM
subclasses or any otherasyncio
code creatingevent_loop
s will fail in Colab with the following exceptionRuntimeError: Cannot run the event loop while another loop is running
.On top of that, an utils function named
in_notebook
has been included so as to identify whether the code is running in a notebook, and if so, usenest-asyncio
so as to be able to successfully useasyncio
.Thanks @burtenshaw for reporting and @gabrielmbmb for the hints!