Skip to content

Commit f3b6340

Browse files
Don't block the event loop when exporting with nbconvert (#655)
1 parent db46446 commit f3b6340

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

jupyter_server/nbconvert/handlers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
import zipfile
77

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

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

0 commit comments

Comments
 (0)