8000 fix event loop is already running bug on Linux · jupyter-server/jupyter-scheduler@9f5dc56 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f5dc56

Browse files
committed
fix event loop is already running bug on Linux
1 parent 646e6c9 commit 9f5dc56

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

jupyter_scheduler/scheduler.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import multiprocessing as mp
12
import os
23
import random
34
import shutil
4-
from multiprocessing import Process
55
from typing import Dict, Optional, Type, Union
66

77
import fsspec
@@ -403,7 +403,15 @@ def create_job(self, model: CreateJob) -> str:
403403
staging_paths = self.get_staging_paths(DescribeJob.from_orm(job))
404404
self.copy_input_file(model.input_uri, staging_paths["input"])
405405

406-
p = Process(
406+
# The MP context forces new processes to not be forked on Linux.
407+
# This is necessary because `asyncio.get_event_loop()` is bugged in
408+
# forked processes in Python versions below 3.12. This method is
409+
# called by `jupyter_core` by `nbconvert` in the default executor.
410+
#
411+
# See: https://github.com/python/cpython/issues/66285
412+
# See also: https://github.com/jupyter/jupyter_core/pull/362
413+
mp_ctx = mp.get_context("spawn")
414+
p = mp_ctx.Process(
407415
target=self.execution_manager_class(
408416
job_id=job.job_id,
409417
staging_paths=staging_paths,

0 commit comments

Comments
 (0)
0