1

実行前に任意の関数をピクルするために後で使用できるデコレータを構築しようとしていますが、次のエラーが発生しています

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()

どうすればこの問題を解決できますか?

4

0 に答える 0