← 输入框|bugs.python.org|刷新

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

作者 jaraco
收信人 alexandre.vassalotti, belopolsky, benjamin.peterson, bpb, brett.cannon, ehuss, facundobatista, fmitha, georg.brandl, gvanrossum, jafo, jaraco, jarpa, kylev, loewis, lukasz.langa, nnorwitz, pitrou, python-dev, sbt, slallum, taleinat, tseaver, vstinner, zbysz, zseil
日期 2018-01-28.15:04:51
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1517151891.55.0.467229070634.issue1692335@psf.upfronthosting.co.za>
In-reply-to
内容
@slallum, That does seem to be a problem, though I do observe that the issue reported by bdb with CalledProcessError is no longer an issue:

>>> import subprocess, pickle
>>> try:
...   subprocess.check_call(['python', '-c', 'raise SystemExit(1)'])
... except Exception as e:
...   pickle.loads(pickle.dumps(e))
... 
CalledProcessError(1, ['python', '-c', 'raise SystemExit(1)'])

Looking into how CalledProcessError is defined (https://github.com/python/cpython/blob/79db11ce99332d62917be9d03b31494b1ff2f96a/Lib/subprocess.py#L60) may shed some light on the recommended way to make a pickleable Exception class that takes more than one argument.

Hmm. It seems it does it by not calling the superclass __init__. Indeed, following that model it seems to work:

import pickle
class MultipleArgumentsError(Exception):
    def __init__(self, a, b):
        self.a = a
        self.b = b

err = pickle.loads(pickle.dumps(MultipleArgumentsError('a', 'b')))
assert err.a == 'a'
assert err.b == 'b'
历史
日期 用户 动作 参数
2018-01-28 15:04:51jaraco修改recipients: + jaraco, gvanrossum, loewis, nnorwitz, brett.cannon, georg.brandl, facundobatista, jafo, ehuss, tseaver, belopolsky, zseil, fmitha, pitrou, vstinner, taleinat, alexandre.vassalotti, benjamin.peterson, jarpa, bpb, zbysz, kylev, lukasz.langa, python-dev, sbt, slallum
2018-01-28 15:04:51jaraco修改messageid: <1517151891.55.0.467229070634.issue1692335@psf.upfronthosting.co.za>
2018-01-28 15:04:51jaraco链接issue1692335 messages
2018-01-28 15:04:51jaraco创建