我正在尝试构建一个装饰器,以后可以在执行之前使用它来挑选任何函数,但是我收到了以下错误
PicklingError at /
Can't pickle <function wow at 0x105ff9488>: it's not the same object as apps.sandbox_app.tasks.wow
这是我的装饰者
# -*- coding: utf-8 -*-
import base64
import pickle
from models import Task
from functools import wraps
def register(func):
""" Decorate a function to print its arguments.
"""
@wraps(func)
def executable(*args, **kwargs):
return store_task_to_model(func)
def store_task_to_model(x):
Task.objects.create(
task = base64.b64encode(pickle.dumps(x)),
status = 'P'
).save()
return executable
这是装饰者注册
from dj_cron.task import register
@register
def wow():
x = 2 * 3
return x
以及实际调用函数哇如下
call.py
wow()
任何想法如何解决这个问题?