multiprocessing race condition on flushing stdout, deadlocks child on exit
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
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- distributed-systems
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện multiprocessing được cung cấp trên Linux với các phiên bản Python được báo cáo, sau đó kiểm tra multiprocessing Queue và đường dẫn thoát của tiến trình con, bao gồm các đường dẫn multiprocessing/process.py và multiprocessing/popen_fork.py được hiển thị trong traceback. Công việc được xem là hoàn tất khi các worker thực hiện join một cách ổn định sau khi các mục trong Queue được lấy ra, với coverage hồi quy cho trường hợp đã tái hiện.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I experienced deadlocks when using the logging example for multiprocessing, where a QueueHandler is used.
I found that sometimes a multiprocessing process is not terminating, when it has put an element in a Queue,
even if the parent process runs a thread to empty the queue and successfully retrieved the item.
The worker looks like this:
def worker(q):
q.put(current_process().name)
return
and while this works:
workers = []
for i in range(15):
p = Process(target=worker, args=(logq,), name=f"Worker {i+1}")
workers.append(p)
for p in workers:
p.start()
time.sleep(.1)
removing the sleep leads to a very high propability of deadlocking when I then try to join the processes, e.g,:
for w in workers:
print(f'trying to join on {w.name}, alive={w.is_alive()}, exitcode={w.exitcode}', w.name, w.is_alive(), w.exitcode)
w.join()
The Process is still marked as alive, hitting Ctrl+C gives this:
trying to join on Worker 14, alive=True, exitcode=None Worker 14 True None
^CTraceback (most recent call last):
File "/home/fls/pybug/deadlock.py", line 43, in <module>
w.join()
File "/usr/lib/python3.10/multiprocessing/process.py", line 149, in join
res = self._popen.wait(timeout)
File "/usr/lib/python3.10/multiprocessing/popen_fork.py", line 43, in wait
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
File "/usr/lib/python3.10/multiprocessing/popen_fork.py", line 27, in poll
pid, sts = os.waitpid(self.pid, flag)
KeyboardInterrupt
Can reproduce using Python 3.9.10 and 3.10.4 on Linux:
import time
import threading
from multiprocessing import Process, Queue, current_process
def logger_thread(q: Queue):
while True:
record = q.get()
if record is None:
break
print("logrecord: ", record)
def worker(q):
q.put(current_process().name)
return
logq = Queue()
lp = threading.Thread(target=logger_thread, args=(logq,), daemon=True)
lp.start()
workers = []
for i in range(15):
p = Process(target=worker, args=(logq,), name=f"Worker {i+1}")
workers.append(p)
print("starting workers")
for p in workers:
p.start()
# no deadlock when added:
# time.sleep(.1)
print("waiting a bit")
time.sleep(1)
print("trying to join workers")
for w in workers:
print(f'trying to join on {w.name}, alive={w.is_alive()}, exitcode={w.exitcode}', w.name, w.is_alive(), w.exitcode)
w.join()
print(f'joined on {w.name}', w.name)
logq.put(None)
lp.join()
- 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
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
area/auth bug comp/agent P3 platform/discord type/security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#117848 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
bancolombia/sentinel#23 ·
-
test md Đang mởCI
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100