File tree 1 file changed +11
-3
lines changed
jupyter_server/services/nbconvert
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
2
3
+ try :
4
+ from anyio .to_thread import run_sync
5
+ except ImportError :
6
+ # fallback on anyio v2 for python version < 3.7
7
+ from anyio import run_sync_in_worker_thread as run_sync
8
+
3
9
from tornado import web
4
10
5
11
from ...base .handlers import APIHandler
8
14
class NbconvertRootHandler (APIHandler ):
9
15
10
16
@web .authenticated
11
- def get (self ):
17
+ async def get (self ):
12
18
try :
13
19
from nbconvert .exporters import base
14
20
except ImportError as e :
15
21
raise web .HTTPError (500 , "Could not import nbconvert: %s" % e ) from e
16
22
res = {}
17
- exporters = base .get_export_names ()
23
+ # Some exporters use the filesystem when instantiating, delegate that
24
+ # to a thread so we don't block the event loop for it.
25
+ exporters = await run_sync (base .get_export_names )
18
26
for exporter_name in exporters :
19
27
try :
20
- exporter_class = base .get_exporter ( exporter_name )
28
+ exporter_class = await run_sync ( base .get_exporter , exporter_name )
21
29
except ValueError :
22
30
# I think the only way this will happen is if the entrypoint
23
31
# is uninstalled while this method is running
You can’t perform that action at this time.
0 commit comments