Commit bf316bce4662160d8e1ad4fb605c303e1ddfdee5
1 parent
b883fd46
Exists in
master
and in
30 other branches
Refactored signals connections
Showing
2 changed files
with
8 additions
and
10 deletions
Show diff stats
colab/__init__.py
1 | from __future__ import absolute_import | 1 | from __future__ import absolute_import |
2 | 2 | ||
3 | -from . import plugins | ||
4 | - | ||
5 | # This will make sure the app is always imported when | 3 | # This will make sure the app is always imported when |
6 | # Django starts so that shared_task will use this app. | 4 | # Django starts so that shared_task will use this app. |
7 | from .celery import app as celery_app # noqa | 5 | from .celery import app as celery_app # noqa |
8 | - |
colab/signals/signals.py
@@ -7,17 +7,18 @@ registered_signals = {} | @@ -7,17 +7,18 @@ registered_signals = {} | ||
7 | signal_instances = {} | 7 | signal_instances = {} |
8 | 8 | ||
9 | 9 | ||
10 | -def reducer(self): | ||
11 | - ''' | 10 | +class ColabSignal(Signal): |
11 | + def __reduce__(self): | ||
12 | + """ | ||
13 | + | ||
12 | In order to send a signal to a celery task, it is necessary to pickle | 14 | In order to send a signal to a celery task, it is necessary to pickle |
13 | the objects that will be used as parameters. However, | 15 | the objects that will be used as parameters. However, |
14 | django.dispatch.Signal has an instance of threading.Lock, which is an | 16 | django.dispatch.Signal has an instance of threading.Lock, which is an |
15 | object that cannot be pickled. Therefore, this function changes the | 17 | object that cannot be pickled. Therefore, this function changes the |
16 | pickle behaviour of Signal, making that only the providind_args of | 18 | pickle behaviour of Signal, making that only the providind_args of |
17 | - Signal to be pickled. | ||
18 | - ''' | ||
19 | - return (Signal, (self.providing_args,)) | ||
20 | -Signal.__reduce__ = reducer | 19 | + Signal to be pickled.""" |
20 | + | ||
21 | + return (ColabSignal, (self.providing_args,)) | ||
21 | 22 | ||
22 | 23 | ||
23 | def register_signal(plugin_name, list_signals): | 24 | def register_signal(plugin_name, list_signals): |
@@ -28,7 +29,7 @@ def register_signal(plugin_name, list_signals): | @@ -28,7 +29,7 @@ def register_signal(plugin_name, list_signals): | ||
28 | else: | 29 | else: |
29 | registered_signals[signal] = [] | 30 | registered_signals[signal] = [] |
30 | registered_signals[signal].append(plugin_name) | 31 | registered_signals[signal].append(plugin_name) |
31 | - signal_instances[signal] = Signal() | 32 | + signal_instances[signal] = ColabSignal() |
32 | 33 | ||
33 | 34 | ||
34 | def connect_signal(signal_name, sender, handling_method): | 35 | def connect_signal(signal_name, sender, handling_method): |