test_forkserver_sigkill: join() can return before the child sets the event
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
閱讀Lib/test/_test_multiprocessing.py,尤其是check_forkserver_death()和test_forkserver_sigkill;問題在於 forkserver 被終止後,子行程設定事件之前join()就可能返回。更新事件檢查,讓它等待並設定逾時時間,然後執行針對 forkserver 的測試。完成標準是:測試給子行程留出設定事件的時間,並繼續檢查預期的結束碼。
由索引模型根據 Issue 內容生成。
描述
Bug report
Bug description:
test_forkserver_sigkill failed once during a full ./python.exe -m test -j0 run on my machine (macOS 27.0.1, Apple M3, pydebug build of main at 1705e512b30). The load average was around 65 at the time. It passes when run on its own.
test test.test_multiprocessing_forkserver.test_processes failed -- Traceback (most recent call last):
File "Lib/test/_test_multiprocessing.py", line 1007, in test_forkserver_sigkill
self.check_forkserver_death(signal.SIGKILL)
File "Lib/test/_test_multiprocessing.py", line 997, in check_forkserver_death
self.assertTrue(evt.is_set())
AssertionError: False is not true
(paths shortened)
This is the same failure as gh-78221 (bpo-34040). It was worked around in 2018 by shortening the child's delay relative to the parent's sleep (07888e1cce), but the race is still there.
check_forkserver_death() kills the forkserver right after starting the first process. After a SIGKILL, the forkserver can no longer report that child's exit status: proc.join() gets EOF on the status pipe, and Popen.poll() in Lib/multiprocessing/popen_forkserver.py sets returncode to 255 immediately. The child may still be running at that point. The test then checks evt.is_set(), which only passes if the child has set the event by then (within the 1 second sleep plus the time proc2 takes). The next line already accepts exit code 255 for the case where the forkserver was killed.
SIGINT is not affected: the forkserver ignores it, stays alive and reports the real exit code.
To reproduce it reliably, stop the first child with SIGSTOP for a few seconds after killing the forkserver:
Reproducer
import multiprocessing as mp, os, signal, threading, time
from multiprocessing.forkserver import _forkserver
def sleep_and_set(evt, delay=0.0):
time.sleep(delay)
evt.set()
if __name__ == '__main__':
mp.set_start_method('forkserver')
_forkserver.ensure_running()
evt = mp.Event()
proc = mp.Process(target=sleep_and_set, args=(evt, 0.5))
proc.start()
os.kill(_forkserver._forkserver_pid, signal.SIGKILL)
# Simulate the child not getting CPU time for 3 seconds.
os.kill(proc.pid, signal.SIGSTOP)
threading.Timer(3.0, os.kill, (proc.pid, signal.SIGCONT)).start()
time.sleep(1.0)
proc.join()
print(proc.exitcode, evt.is_set()) # 255 False
print(evt.wait(60)) # True: the child did run, later
Waiting for the event with a timeout, instead of checking it right after join(), fixes it.
The same code is in 3.13, 3.14 and 3.15.
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS, Linux
Linked PRs
- gh-160296
- 主要語言
- Python
- 星號
- 77.7k
- 分支
- 38.3k
- 平均合併
- 12 小時 27 分鐘
- 30 天內合併 PR
- 645
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/cpython 的其他 Issue
-
tests topic-profiling type-bug
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 84/100
維護者通常 1 天內回覆
-
interpreter-core type-feature
難度 1/5 1 小時以內 新手友好度 78/100
python/cpython#160109 · 1 則留言 ·
維護者通常 1 天內回覆
-
extension-modules type-bug
難度 2/5 1-3 小時 新手友好度 72/100
python/cpython#160001 · 3 則留言 ·
維護者通常 1 天內回覆
-
stdlib topic-XML type-bug
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
相似的 Issue
-
style: article/section 📝 system: cloud.rc ☁️ system: security 🔐
難度 2/5 1-3 小時 新手友好度 65/100
uabrc/uabrc.github.io#1262 ·
-
documentation
難度 2/5 1-3 小時 新手友好度 70/100
NCAR/miles-credit#526 ·
-
documentation
難度 1/5 1-3 小時 新手友好度 76/100
conda/conda-lock#957 ·
維護者通常 1 天內回覆
-
Type: Bug
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
aws-samples/sample-per-model-bedrock#464 ·
維護者通常 1 天內回覆