【发布时间】:2013-11-06 17:14:47
【问题描述】:
我正在尝试实现一个消息队列系统以将操作推送到 AdWords API。
class Call(object):
@celery.task(filter=task_method)
def MUTATE(self, operations):
assert hasattr(self, '__throwaway_service')
with self.__throwaway_service as sm:
response = sm.mutate(operations)
return response
由于我不能将服务实例用作参数(服务具有向 API 发送“get”或“mutate”请求的方法),我将其设置为外部属性,并在该特定服务的所有操作都完成时将其删除发送到 MQ。
'operations' 是包含字符串或 unicode 键和值的字典列表。
我还是得到了
PicklingError: Can't pickle <type 'instancemethod'>: attribute lookup __builtin__.instancemethod failed
我收到这个错误是因为 celery 任务完全使用了实例方法吗?实现这一点的最佳和 Pythonic 方式是什么?
【问题讨论】:
-
我认为问题在于您的任务方法在一个类中,您可以尝试将您的“MUTATE”方法转换为一个普通的python函数并以这种方式测试它是否有效?跨度>
-
好吧,问题出在服务实例上。我需要那个,因为它是在我推动操作的那个服务上。因此,如果我将方法作为函数,则 service 必须是一个参数,它不能,因为它不可选择。不幸的是,班级没有任何变化。我只是卡住了
标签: python celery message-queue mq google-ads-api