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

just_run does not close event loop it creates #249

Closed
akx opened this issue Sep 7, 2022 · 2 comments
Closed

just_run does not close event loop it creates #249

akx opened this issue Sep 7, 2022 · 2 comments

Comments

@akx
Copy link

akx commented Sep 7, 2022

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:

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

@davidbrochart
Copy link
Member

Thanks @akx for opening an issue.
I am experimenting with a new implementation in #250.

@akx
Copy link
Author

akx commented Feb 13, 2023

Welp, just_run is no more, so I guess this was fixed in #259.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants