Skip to content

Commit a4a0a52

Browse files
committed
Fix nbconvert handler run_sync()
1 parent 923a828 commit a4a0a52

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

jupyter_server/nbconvert/handlers.py

+18-11
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def respond_zip(handler, name, output, resources):
4040
zip_filename = os.path.splitext(name)[0] + ".zip"
4141
handler.set_attachment_header(zip_filename)
4242
handler.set_header("Content-Type", "application/zip")
43-
handler.set_header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
43+
handler.set_header(
44+
"Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"
45+
)
4446

4547
# Prepare the zip file
4648
buffer = io.BytesIO()
@@ -119,7 +121,7 @@ async def get(self, format, path):
119121
# Exporting can take a while, delegate to a thread so we don't block the event loop
120122
try:
121123
output, resources = await run_sync(
122-
exporter.from_notebook_node(nb, resources=resource_dict)
124+
exporter.from_notebook_node, nb, resource_dict
123125
)
124126
except Exception as e:
125127
self.log.exception("nbconvert failed: %s", e)
@@ -135,9 +137,13 @@ async def get(self, format, path):
135137

136138
# MIME type
137139
if exporter.output_mimetype:
138-
self.set_header("Content-Type", "%s; charset=utf-8" % exporter.output_mimetype)
140+
self.set_header(
141+
"Content-Type", "%s; charset=utf-8" % exporter.output_mimetype
142+
)
139143

140-
self.set_header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
144+
self.set_header(
145+
"Cache-Control", "no-store, no-cache, must-revalidate, max-age=0"
146+
)
141147
self.finish(output)
142148

143149

@@ -146,20 +152,19 @@ class NbconvertPostHandler(JupyterHandler):
146152
SUPPORTED_METHODS = ("POST",)
147153

148154
@web.authenticated
149-
def post(self, format):
155+
async def post(self, format):
150156
exporter = get_exporter(format, config=self.config)
151157

152158
model = self.get_json_body()
153159
name = model.get("name", "notebook.ipynb")
154160
nbnode = from_dict(model["content"])
155161

156162
try:
157-
output, resources = exporter.from_notebook_node(
163+
output, resources = await run_sync(
164+
exporter.from_notebook_node,
158165
nbnode,
159-
resources={
160-
"metadata": {
161-
"name": name[: name.rfind(".")],
162-
},
166+
{
167+
"metadata": {"name": name[: name.rfind(".")]},
163168
"config_dir": self.application.settings["config_dir"],
164169
},
165170
)
@@ -171,7 +176,9 @@ def post(self, format):
171176

172177
# MIME type
173178
if exporter.output_mimetype:
174-
self.set_header("Content-Type", "%s; charset=utf-8" % exporter.output_mimetype)
179+
self.set_header(
180+
"Content-Type", "%s; charset=utf-8" % exporter.output_mimetype
181+
)
175182

176183
self.finish(output)
177184

0 commit comments

Comments
 (0)