File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed
jupyter_server/services/nbconvert Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change 11import json
22
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+
39from tornado import web
410
511from ...base .handlers import APIHandler
814class NbconvertRootHandler (APIHandler ):
915
1016 @web .authenticated
11- def get (self ):
17+ async def get (self ):
1218 try :
1319 from nbconvert .exporters import base
1420 except ImportError as e :
1521 raise web .HTTPError (500 , "Could not import nbconvert: %s" % e ) from e
1622 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 )
1826 for exporter_name in exporters :
1927 try :
20- exporter_class = base .get_exporter ( exporter_name )
28+ exporter_class = await run_sync ( base .get_exporter , exporter_name )
2129 except ValueError :
2230 # I think the only way this will happen is if the entrypoint
2331 # is uninstalled while this method is running
You can’t perform that action at this time.
0 commit comments