Browse Source

Task.__reduce__: Properly pickle task instances created with the task decorator

Ask Solem 15 years ago
parent
commit
ac9b4a7f83
1 changed files with 7 additions and 0 deletions
  1. 7 0
      celery/task/base.py

+ 7 - 0
celery/task/base.py

@@ -16,6 +16,10 @@ from celery.task.schedules import schedule
 from celery.task.sets import TaskSet, subtask
 
 
+def _unpickle_task(name):
+    return tasks[name]
+
+
 class TaskType(type):
     """Metaclass for tasks.
 
@@ -217,6 +221,9 @@ class Task(object):
     def __call__(self, *args, **kwargs):
         return self.run(*args, **kwargs)
 
+    def __reduce__(self):
+        return (_unpickle_task, (self.name, ), None)
+
     def run(self, *args, **kwargs):
         """The body of the task executed by the worker.