From d2015290b80bfdaa6ebb990cdccc0155921696f5 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Tue, 18 Jan 2022 19:30:42 +0100 Subject: [PATCH] Fix nbconvert handler run_sync() (#667) --- jupyter_server/nbconvert/handlers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/jupyter_server/nbconvert/handlers.py b/jupyter_server/nbconvert/handlers.py index 29a8f10e51..7cad017cc7 100644 --- a/jupyter_server/nbconvert/handlers.py +++ b/jupyter_server/nbconvert/handlers.py @@ -119,7 +119,7 @@ async def get(self, format, path): # Exporting can take a while, delegate to a thread so we don't block the event loop try: output, resources = await run_sync( - exporter.from_notebook_node(nb, resources=resource_dict) + lambda: exporter.from_notebook_node(nb, resources=resource_dict) ) except Exception as e: self.log.exception("nbconvert failed: %s", e) @@ -146,7 +146,7 @@ class NbconvertPostHandler(JupyterHandler): SUPPORTED_METHODS = ("POST",) @web.authenticated - def post(self, format): + async def post(self, format): exporter = get_exporter(format, config=self.config) model = self.get_json_body() @@ -154,14 +154,14 @@ def post(self, format): nbnode = from_dict(model["content"]) try: - output, resources = exporter.from_notebook_node( - nbnode, - resources={ - "metadata": { - "name": name[: name.rfind(".")], + output, resources = await run_sync( + lambda: exporter.from_notebook_node( + nbnode, + resources={ + "metadata": {"name": name[: name.rfind(".")]}, + "config_dir": self.application.settings["config_dir"], }, - "config_dir": self.application.settings["config_dir"], - }, + ) ) except Exception as e: raise web.HTTPError(500, "nbconvert failed: %s" % e) from e