fsu*_*ser 1 python django pickle celery
我在 django 应用程序中使用 celery。如果发生故障,我会引发一个自定义异常,该异常是用此类定义的:
class CustomException(Exception):
def __init__(self, err_input, err_info=''):
self.err_key, self.err_msg, self.app_domain = err_input
self.message = self.err_msg
super(CustomException, self).__init__(self.message)
self.err_info = err_info
def __str__(self):
return '[{}] {}'.format(str(self.err_key), str(self.err_msg))
def __repr__(self):
return self.message
Run Code Online (Sandbox Code Playgroud)
用于error_info内部日志记录目的。如果我抛出在相关 celery 任务中收到的消息:
{
"task_id": "0dfd5ef3-0df1-11eb-b74a-0242ac110002",
"status": "FAILURE",
"result": {
"exc_type": "MaybeEncodingError",
"exc_message": [
"'PicklingError(\"Can\\'t pickle <class \\'module.CustomException\\'>: it\\'s not the same object as module.CustomException\")'",
"\"(1, <ExceptionInfo: CustomException('Error message')>, None)\""
],
"exc_module": "billiard.pool"
},
"traceback": null,
"children": []
}
Run Code Online (Sandbox Code Playgroud)
我在异常类中配置了什么错误?
解决方案是删除对 的调用super(CustomException, self).__init__(self.message)。
从我读到的内容来看,Pickling 期望一个只有 1 个参数的 init 函数。因此,为了避免该错误,我要么必须更改 my 的 initCustomException以仅接受 1 个参数,要么删除对 super 的调用
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |