diff --git a/jupyter_server/services/nbconvert/handlers.py b/jupyter_server/services/nbconvert/handlers.py index a15dd3e314..e6d99e3bd4 100644 --- a/jupyter_server/services/nbconvert/handlers.py +++ b/jupyter_server/services/nbconvert/handlers.py @@ -1,4 +1,5 @@ import json +import asyncio from anyio.to_thread import run_sync from tornado import web @@ -6,6 +7,8 @@ from ...base.handlers import APIHandler +LOCK = asyncio.Lock() + class NbconvertRootHandler(APIHandler): @web.authenticated @@ -20,7 +23,8 @@ async def get(self): exporters = await run_sync(base.get_export_names) for exporter_name in exporters: try: - exporter_class = await run_sync(base.get_exporter, exporter_name) + async with LOCK: + exporter_class = await run_sync(base.get_exporter, exporter_name) except ValueError: # I think the only way this will happen is if the entrypoint # is uninstalled while this method is running