Skip to content

Commit

Permalink
Don't block the event loop when exporting with nbconvert
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Jan 11, 2022
1 parent db46446 commit 9e10e59
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion jupyter_server/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from nbformat import from_dict
from tornado import web
from tornado.log import app_log
from anyio.to_thread import run_sync

from ..base.handlers import FilesRedirectHandler
from ..base.handlers import JupyterHandler
Expand Down Expand Up @@ -115,8 +116,10 @@ async def get(self, format, path):
if ext_resources_dir:
resource_dict["metadata"]["path"] = ext_resources_dir

# Some exporters use the filesystem, delegate that
# to a thread so we don't block the event loop for it.
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

0 comments on commit 9e10e59

Please sign in to comment.