-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Description
If there is no running event loop, nbclient.util.just_run
, as used by nbclient.util.run_sync
, as used by the synchronous NotebookClient.execute()
wrapper, creates a new event loop but never closes it:
Lines 40 to 60 in 4e99419
def just_run(coro: Awaitable) -> Any: | |
"""Make the coroutine run, even if there is an event loop running (using nest_asyncio)""" | |
try: | |
loop = asyncio.get_running_loop() | |
except RuntimeError: | |
loop = None | |
if loop is None: | |
had_running_loop = False | |
loop = asyncio.new_event_loop() | |
asyncio.set_event_loop(loop) | |
else: | |
had_running_loop = True | |
if had_running_loop: | |
# if there is a running loop, we patch using nest_asyncio | |
# to have reentrant event loops | |
check_ipython() | |
import nest_asyncio | |
nest_asyncio.apply() | |
check_patch_tornado() | |
return loop.run_until_complete(coro) |
This could cause ResourceWarnings: jupyter/nbconvert#1856
Metadata
Metadata
Assignees
Labels
No labels