New submission from Toshio Kuratomi <[email protected]>:
I was trying to use multiprocessing (via a
concurrent.futures.ProcessPoolExecutor) and encountered an error when pickling
a custom Exception. On closer examination I was able to create a simple test
case that only involves pickle:
import pickle
class StrRegexError(Exception):
def __init__(self, *, pattern):
self.pattern = pattern
data = pickle.dumps(StrRegexError(pattern='test'))
instance = pickle.loads(data)
[pts/11@peru /srv/ansible]$ python3.8 ~/p.py
Traceback (most recent call last):
File "/home/badger/p.py", line 7, in <module>
instance = pickle.loads(data)
TypeError: __init__() missing 1 required keyword-only argument: 'pattern'
pickle can handle mandatory keyword args in other classes derived from object;
it's only classes derived from Exception that have issues.
----------
components: Library (Lib)
messages: 371057
nosy: a.badger
priority: normal
severity: normal
status: open
title: pickling exceptions with mandatory keyword args will traceback
versions: Python 3.6, Python 3.7, Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40917>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com