celery.utils.serialization
¶
Utilities for safely pickling exceptions.
- exception celery.utils.serialization.UnpickleableExceptionWrapper(exc_module, exc_cls_name, exc_args, text=None)[源代码]¶
Wraps unpickleable exceptions.
- 参数:
exc_module (str) -- See
exc_module
.exc_cls_name (str) -- See
exc_cls_name
.exc_args (Tuple[Any, ...]) -- See
exc_args
.
示例
>>> def pickle_it(raising_function): ... try: ... raising_function() ... except Exception as e: ... exc = UnpickleableExceptionWrapper( ... e.__class__.__module__, ... e.__class__.__name__, ... e.args, ... ) ... pickle.dumps(exc) # Works fine.
- exc_args = None¶
The arguments for the original exception.
- exc_cls_name = None¶
The name of the original exception class.
- exc_module = None¶
The module of the original exception.
- celery.utils.serialization.create_exception_cls(name, module, parent=None)[源代码]¶
Dynamically create an exception class.
- celery.utils.serialization.find_pickleable_exception(exc, loads=<built-in function loads>, dumps=<built-in function dumps>)[源代码]¶
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
Exception
(i.e., it skipsException
,BaseException
andobject
). If that happens you should useUnpickleableException
instead.- 参数:
exc (BaseException) -- An exception instance.
loads -- decoder to use.
dumps -- encoder to use
- 返回:
- Nearest pickleable parent exception class
(except
Exception
and parents), or if the exception is pickleable it will returnNone
.
- 返回类型:
- celery.utils.serialization.get_pickleable_etype(cls, loads=<built-in function loads>, dumps=<built-in function dumps>)[源代码]¶
Get pickleable exception type.
- celery.utils.serialization.get_pickled_exception(exc)[源代码]¶
Reverse of
get_pickleable_exception()
.