Commit 60cd80e 1 parent 7b4f94e commit 60cd80e Copy full SHA for 60cd80e
File tree 3 files changed +20
-2
lines changed
3 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
9
9
in ``anyio.Path ``, newly added in Python 3.13
10
10
- Changed the ``ResourceWarning `` from an unclosed memory object stream to include its
11
11
address for easier identification
12
+ - Fixed ``to_process.run_sync() `` failing to initialize if ``__main__.__file__ `` pointed
13
+ to a file in a nonexistent directory
14
+ (`#696 <https://github.com/agronholm/anyio/issues/696 >`_)
12
15
13
16
**4.4.0 **
14
17
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ def process_worker() -> None:
223
223
main_module_path : str | None
224
224
sys .path , main_module_path = args
225
225
del sys .modules ["__main__" ]
226
- if main_module_path :
226
+ if main_module_path and os . path . isfile ( main_module_path ) :
227
227
# Load the parent's main module but as __mp_main__ instead of
228
228
# __main__ (like multiprocessing does) to avoid infinite recursion
229
229
try :
@@ -234,7 +234,6 @@ def process_worker() -> None:
234
234
sys .modules ["__main__" ] = main
235
235
except BaseException as exc :
236
236
exception = exc
237
-
238
237
try :
239
238
if exception is not None :
240
239
status = b"EXCEPTION"
Original file line number Diff line number Diff line change 4
4
import sys
5
5
import time
6
6
from functools import partial
7
+ from pathlib import Path
7
8
from unittest .mock import Mock
8
9
9
10
import pytest
11
+ from pytest import MonkeyPatch
10
12
11
13
from anyio import (
12
14
CancelScope ,
@@ -113,3 +115,17 @@ async def test_exec_while_pruning() -> None:
113
115
assert idle_workers [0 ][0 ] is real_worker
114
116
finally :
115
117
workers .discard (fake_idle_process )
118
+
119
+
120
+ async def test_nonexistent_main_module (
121
+ monkeypatch : MonkeyPatch , tmp_path : Path
122
+ ) -> None :
123
+ """
124
+ Test that worker process creation won't fail if the detected path to the `__main__`
125
+ module doesn't exist. Regression test for #696.
126
+ """
127
+
128
+ script_path = tmp_path / "badscript"
129
+ script_path .touch ()
130
+ monkeypatch .setattr ("__main__.__file__" , str (script_path / "__main__.py" ))
131
+ await to_process .run_sync (os .getpid )
You can’t perform that action at this time.
0 commit comments