Failure subsclasses BaseException.
BaseException implements the reduce pickle API, in C.
- As a result, you need to override
__reduce__ to impact pickling behavior.
Demonstration—notice that Failure.__getstate__ does c["pickled"] = 1 in its implementation in the dictionary it returns.
Python 3.11.8 (main, Feb 25 2024, 16:39:33) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> from twisted.python.failure import Failure
>>> f = Failure(ZeroDivisionError())
>>> pickle.loads(pickle.dumps(f)).pickled
0
FailuresubsclassesBaseException.BaseExceptionimplements the reduce pickle API, in C.__reduce__to impact pickling behavior.Demonstration—notice that
Failure.__getstate__doesc["pickled"] = 1in its implementation in the dictionary it returns.