MCPcopy Create free account
hub / github.com/celery/celery / find_pickleable_exception

Function find_pickleable_exception

celery/utils/serialization.py:38–66  ·  view source on GitHub ↗

Find first pickleable exception base class. With an exception instance, iterate over its super classes (by MRO) and find the first super exception that's pickleable. It does not go below :exc:`Exception` (i.e., it skips :exc:`Exception`, :class:`BaseException` and :class:`object`).

(exc, loads=pickle.loads,
                              dumps=pickle.dumps)

Source from the content-addressed store, hash-verified

36
37
38def find_pickleable_exception(exc, loads=pickle.loads,
39 dumps=pickle.dumps):
40 """Find first pickleable exception base class.
41
42 With an exception instance, iterate over its super classes (by MRO)
43 and find the first super exception that's pickleable. It does
44 not go below :exc:`Exception` (i.e., it skips :exc:`Exception`,
45 :class:`BaseException` and :class:`object`). If that happens
46 you should use :exc:`UnpickleableException` instead.
47
48 Arguments:
49 exc (BaseException): An exception instance.
50 loads: decoder to use.
51 dumps: encoder to use
52
53 Returns:
54 Exception: Nearest pickleable parent exception class
55 (except :exc:`Exception` and parents), or if the exception is
56 pickleable it will return :const:`None`.
57 """
58 exc_args = getattr(exc, 'args', [])
59 for supercls in itermro(exc.__class__, unwanted_base_classes):
60 try:
61 superexc = supercls(*exc_args)
62 loads(dumps(superexc))
63 except Exception: # pylint: disable=broad-except
64 pass
65 else:
66 return superexc
67
68
69def itermro(cls, stop):

Callers 1

get_pickleable_exceptionFunction · 0.85

Calls 1

itermroFunction · 0.85

Tested by

no test coverage detected