Skip to content

Commit f3157f3

Browse files
authored
Set the default work start method to spawn on MacOS (#16089)
1 parent 0fd3d54 commit f3157f3

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

src/lightning_app/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
2828
### Changed
2929

3030

31+
- The default `start_method` for creating Work processes locally on MacOS is now 'spawn' (previously 'fork') ([#16089](https://github.com/Lightning-AI/lightning/pull/16089))
32+
33+
3134
- The utility `lightning.app.utilities.cloud.is_running_in_cloud` now returns `True` during loading of the app locally when running with `--cloud` ([#16045](https://github.com/Lightning-AI/lightning/pull/16045))
3235

3336

37+
3438
### Deprecated
3539

3640
-

src/lightning_app/core/work.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class LightningWork:
5151

5252
_run_executor_cls: Type[WorkRunExecutor] = WorkRunExecutor
5353
# TODO: Move to spawn for all Operating System.
54-
_start_method = "spawn" if sys.platform == "win32" else "fork"
54+
_start_method = "spawn" if sys.platform in ("darwin", "win32") else "fork"
5555

5656
def __init__(
5757
self,

tests/tests_app/runners/backends/__init__.py

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from unittest import mock
2+
from unittest.mock import MagicMock, Mock
3+
4+
from lightning_app import LightningApp, LightningWork
5+
from lightning_app.runners.backends import MultiProcessingBackend
6+
7+
8+
@mock.patch("lightning_app.runners.backends.mp_process.multiprocessing")
9+
def test_backend_create_work_with_set_start_method(multiprocessing_mock):
10+
backend = MultiProcessingBackend(entrypoint_file="fake.py")
11+
work = Mock(spec=LightningWork)
12+
work._start_method = "test_start_method"
13+
14+
app = LightningApp(work)
15+
app.caller_queues = MagicMock()
16+
app.delta_queue = MagicMock()
17+
app.readiness_queue = MagicMock()
18+
app.error_queue = MagicMock()
19+
app.request_queues = MagicMock()
20+
app.response_queues = MagicMock()
21+
app.copy_request_queues = MagicMock()
22+
app.copy_response_queues = MagicMock()
23+
app.flow_to_work_delta_queues = MagicMock()
24+
25+
backend.create_work(app=app, work=work)
26+
multiprocessing_mock.get_context.assert_called_with("test_start_method")
27+
multiprocessing_mock.get_context().Process().start.assert_called_once()

tests/tests_app/runners/test_multiprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def run(self):
6868
assert _get_context().value == "work"
6969

7070

71-
class ContxtFlow(LightningFlow):
71+
class ContextFlow(LightningFlow):
7272
def __init__(self):
7373
super().__init__()
7474
self.work = ContextWork()
@@ -83,7 +83,7 @@ def run(self):
8383

8484
def test_multiprocess_runtime_sets_context():
8585
"""Test that the runtime sets the global variable COMPONENT_CONTEXT in Flow and Work."""
86-
MultiProcessRuntime(LightningApp(ContxtFlow())).dispatch()
86+
MultiProcessRuntime(LightningApp(ContextFlow())).dispatch()
8787

8888

8989
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)