Can't use XMLRPC errors with multiprocessing and pickle
Đang mở
Chưa có ai nhận issue này.
topic-multiprocessing
type-bug
- 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
Mô tả
Can't use XMLRPC errors with multiprocessing and pickle modules. Multiprocessing freezes.
Bug example
from multiprocessing import Pool
from xmlrpc.client import ProtocolError
def raise_error(_):
raise ProtocolError("1", 2, "3", {})
Pool(1).map(raise_error, (["A", 5]))
Expected output
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\multiprocessing\pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "C:\Program Files\Python310\lib\multiprocessing\pool.py", line 48, in mapstar
return list(map(*args))
File "C:\Users\ppatrin\Projects\test.py", line 6, in raise_error
raise ProtocolError("1", 2, "3", {})
xmlrpc.client.ProtocolError: <ProtocolError for 1: 2 3>
Actual output
"C:\Program Files\Python310\python.exe" C:/Users/ppatrin/Projects/test.py
Exception in thread Thread-3 (_handle_results):
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Program Files\Python310\lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python310\lib\multiprocessing\pool.py", line 576, in _handle_results
task = get()
File "C:\Program Files\Python310\lib\multiprocessing\connection.py", line 256, in recv
return _ForkingPickler.loads(buf.getbuffer())
TypeError: ProtocolError.__init__() missing 4 required positional arguments: 'url', 'errcode', 'errmsg', and 'headers'
And multiprocessing processes frozes.
Real problem
import pickle
from xmlrpc.client import ProtocolError
pickle.loads(pickle.dumps(ProtocolError(1, "2", 3, {})))
>>> TypeError: __init__() missing 4 required positional arguments: 'url', 'errcode', 'errmsg', and 'headers'
How to fix
We should fix a super call in exception method initializer.
class ProtocolError(Error):
"""Indicates an HTTP protocol error."""
def __init__(self, url, errcode, errmsg, headers):
--- Error.__init__(self)
+++ Error.__init__(self, url, errcode, errmsg, headers)
self.url = url
self.errcode = errcode
self.errmsg = errmsg
self.headers = headers
Your environment
- CPython versions tested on: 3.10.4
- Operating system and architecture: Windows 11 and Ubuntu 20.04.
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 từ trình khởi tạo của ProtocolError trong mô-đun xmlrpc.client và tái hiện quy trình round-trip bằng pickle được nêu trong issue. Công việc hoàn tất khi ProtocolError có thể được pickle và unpickle thành công, đồng thời ví dụ multiprocessing không còn bị treo khi trả về lỗi ожида kiến.
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
- api, backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 38/100