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

Don't block the event loop when exporting with nbconvert #655

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion jupyter_server/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import zipfile

from anyio.to_thread import run_sync
from ipython_genutils import text
from ipython_genutils.py3compat import cast_bytes
from nbformat import from_dict
Expand Down Expand Up @@ -115,8 +116,11 @@ async def get(self, format, path):
if ext_resources_dir:
resource_dict["metadata"]["path"] = ext_resources_dir

# Exporting can take a while, delegate to a thread so we don't block the event loop
try:
output, resources = exporter.from_notebook_node(nb, resources=resource_dict)
output, resources = await run_sync(
exporter.from_notebook_node(nb, resources=resource_dict)
)
except Exception as e:
self.log.exception("nbconvert failed: %s", e)
raise web.HTTPError(500, "nbconvert failed: %s" % e) from e
Expand Down