Inconsistent KeyboardInterrupt Handling in multiprocessing due to Context Manager Order
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
Bug description:
When using multiprocessing.Manager with concurrent.futures.ProcessPoolExecutor, there is a particular ordering of the context managers that results in multiprocessing.managers.py hanging in the method serve_forever, forever. This can be triggered by raising a KeyboardInterrupt while the child process(es), here something, are busy. The ordering that leads to the bug is: Manager first, then ProcessPoolExecutor inside.
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
from time import sleep
def something():
sleep(10)
# Uncomment one of the following blocks
### Works correctly:
# # Interrupt with CTRL+C while `something` is busy
# # Takes just one KeyboardInterrupts to terminate fully
# with ProcessPoolExecutor() as executor:
# futures = []
# with multiprocessing.Manager() as manager:
# futures.append(executor.submit(something))
#
# for f in futures:
# f.result()
### Doesn't work correctly, will hang often, try it a few times:
# # Interrupt with CTRL+C while `something` is busy
# # Takes one KeyboardInterrupts to get stuck, and another to terminate fully
# with multiprocessing.Manager() as manager:
# with ProcessPoolExecutor() as executor:
# futures = [executor.submit(something)]
#
# for f in futures:
# f.result()
I am not too familiar with the exact inner workings of these two context managers, but as a user, there was at least nothing to make me aware that the 2nd example is bad. If it's not a bug, and just incorrect ordering, perhaps ProcessPoolExecutor could raise an exception or print a warning that it shouldn't be used inside a Manager context in such a way.
CPython versions tested on:
3.9, 3.10, 3.11, 3.12
Operating systems tested on:
Linux
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.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện hai thứ tự của các context manager với ví dụ ProcessPoolExecutor và multiprocessing.Manager được cung cấp, sau đó kiểm tra multiprocessing.managers.py tại serve_forever và các đường dẫn shutdown liên quan. Được xem là hoàn tất khi thứ tự có vấn đề không còn bị treo sau KeyboardInterrupt và cả hai thứ tự đều kết thúc một cách nhất quán; issue không nêu tên tệp kiểm thử nào.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- distributed-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100