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

Đang mở
#92,881 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
operating-systems

Hướng nghiên cứu

Bắt đầu bằng cách lần theo multiprocessing.Process.is_alive(), luồng Popen.poll() và Process.join() trong khi tái hiện ví dụ os.waitpid() đồng thời trên Linux. So sánh cách mỗi luồng xác định rằng tiến trình con đã thoát, sau đó bổ sung phạm vi kiểm thử hồi quy cho thấy is_alive() trả về false sau khi tiến trình con đã được chờ và join() vẫn hoàn tất ngay lập tức.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

topic-multiprocessing type-bug

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
Ngôn ngữ chính
Python
Star
77.2k
Fork
36k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
558

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/cpython

Tất cả issue của python/cpython

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.