Skip to content

Commit 9ee0a8b

Browse files
[1.x] Fix "event loop is already running" bug on Linux (#454)
* fix event loop is already running bug on Linux * Update Playwright Snapshots --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent b54bb99 commit 9ee0a8b

File tree

2 files changed

+10
-2
lines changed

2 files 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,
Loading

0 commit comments

Comments
 (0)