python / python/cpython

Can't use XMLRPC errors with multiprocessing and pickle

オープン
#93,542 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic-multiprocessing type-bug
主要言語
Python
スター
77.2k
フォーク
36k
平均マージ
1日 9時間
マージ済み PR(30日)
558

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

xmlrpc.client モジュールの ProtocolError 初期化子から始め、issue に示されている pickle のラウンドトリップを再現してください。ProtocolError を正常に pickle 化およびアンピックル化でき、multiprocessing の例が期待されるエラーを返す際にフリーズしなくなれば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api, backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。