diff --git a/colab/__init__.py b/colab/__init__.py index 8a4f90d..d13e951 100644 --- a/colab/__init__.py +++ b/colab/__init__.py @@ -1,8 +1,5 @@ from __future__ import absolute_import -from . import plugins - # This will make sure the app is always imported when # Django starts so that shared_task will use this app. from .celery import app as celery_app # noqa - diff --git a/colab/signals/signals.py b/colab/signals/signals.py index 34ba295..5cceeb2 100644 --- a/colab/signals/signals.py +++ b/colab/signals/signals.py @@ -7,17 +7,18 @@ registered_signals = {} signal_instances = {} -def reducer(self): - ''' +class ColabSignal(Signal): + def __reduce__(self): + """ + In order to send a signal to a celery task, it is necessary to pickle the objects that will be used as parameters. However, django.dispatch.Signal has an instance of threading.Lock, which is an object that cannot be pickled. Therefore, this function changes the pickle behaviour of Signal, making that only the providind_args of - Signal to be pickled. - ''' - return (Signal, (self.providing_args,)) -Signal.__reduce__ = reducer + Signal to be pickled.""" + + return (ColabSignal, (self.providing_args,)) def register_signal(plugin_name, list_signals): @@ -28,7 +29,7 @@ def register_signal(plugin_name, list_signals): else: registered_signals[signal] = [] registered_signals[signal].append(plugin_name) - signal_instances[signal] = Signal() + signal_instances[signal] = ColabSignal() def connect_signal(signal_name, sender, handling_method): -- libgit2 0.21.2