Skip to content

Commit

Permalink
Shut down executor in pyodide pre-execution loop
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 22, 2025
1 parent 797431a commit 6b4ff30
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions nbsite/pyodide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def _execution_process(cls, pipe):
Process execution loop to run in separate process that is used
to evaluate code.
"""
async def loop():
async def event_loop():
while True:
msg = pipe.recv()
if msg['type'] == 'close':
Expand Down Expand Up @@ -301,9 +301,11 @@ async def loop():
content = None
js, js_exports, js_modules, css, global_exports = extract_extensions(code)
pipe.send((content, mime_type, stdout.getvalue(), stderr.getvalue(), js, js_exports, js_modules, css, global_exports))
loop = asyncio.get_running_loop()
await loop.shutdown_default_executor()
cur_task = asyncio.current_task()
await asyncio.gather(*(t for t in asyncio.all_tasks() if t is not cur_task), return_exceptions=True)
asyncio.get_event_loop().run_until_complete(loop())
asyncio.get_event_loop().run_until_complete(event_loop())
pipe.close()

@classmethod
Expand Down

0 comments on commit 6b4ff30

Please sign in to comment.