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
colab/signals/signals.py
... | ... | @@ -7,17 +7,18 @@ registered_signals = {} |
7 | 7 | signal_instances = {} |
8 | 8 | |
9 | 9 | |
10 | -def reducer(self): | |
11 | - ''' | |
10 | +class ColabSignal(Signal): | |
11 | + def __reduce__(self): | |
12 | + """ | |
13 | + | |
12 | 14 | In order to send a signal to a celery task, it is necessary to pickle |
13 | 15 | the objects that will be used as parameters. However, |
14 | 16 | django.dispatch.Signal has an instance of threading.Lock, which is an |
15 | 17 | object that cannot be pickled. Therefore, this function changes the |
16 | 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 | 24 | def register_signal(plugin_name, list_signals): |
... | ... | @@ -28,7 +29,7 @@ def register_signal(plugin_name, list_signals): |
28 | 29 | else: |
29 | 30 | registered_signals[signal] = [] |
30 | 31 | registered_signals[signal].append(plugin_name) |
31 | - signal_instances[signal] = Signal() | |
32 | + signal_instances[signal] = ColabSignal() | |
32 | 33 | |
33 | 34 | |
34 | 35 | def connect_signal(signal_name, sender, handling_method): | ... | ... |