python / python/cpython

multiprocessing.Process.is_alive() incorrect if waitpid() was executed concurrently to it

未關閉
#92,881 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

topic-multiprocessing type-bug
主要語言
Python
星號
77.2k
分支
36k
平均合併
1 天 9 小時
30 天內合併 PR
558

描述

Bug report
As per title. In my case I triggered the os.waitpid() using psutil library, but easily reproducible using os.waitpid, too.

Reproduction:

Python 3.9.5 (default, Nov 18 2021, 16:00:48) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from multiprocessing import Process
>>> import os
>>> import time
>>> p = Process(target=time.sleep, args=(10,))
>>> p.start(); os.waitpid(p.pid, 0)
(17587, 0)
>>> p.is_alive()
True
>>> p.join() # Returns immediately
>>> 

I understand it's something of a corner case; however, join() behaves correctly here, so we definitely have enough info about whether the process is alive.

By the looks of it, if the process has been already waited on, poll() Popen method in multiprocessing returns None, which is interpreted as the process being still alive.

Your environment

  • CPython versions tested on: 3.9.5, but main version seems affected
  • Operating system and architecture: x64 Ubuntu Linux

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先追蹤 multiprocessing.Process.is_alive()、Popen.poll() 路徑和 Process.join(),同時在 Linux 上重現並行 os.waitpid() 範例。比較每條路徑如何判定子行程已結束,然後加入回歸測試涵蓋範圍,顯示在子行程已經被等待之後,is_alive() 會回報 false,且 join() 仍會立即返回。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。