Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Do signal receivers run concurrently?

I'm wondering whether the listener methods that respond to Django signals execute sequentially or concurrently. Essentially, is this:

for object_instance in object_instance_list:
    custom_signal.connect(object_instance.method)
custom_signal.send(self)

Different than this:

for object_instance in object_instance_list:
    object_instance.method()

edit: Made a syntactical correction to the code

like image 343
flimsy Avatar asked Mar 17 '13 19:03

flimsy


Video Answer


1 Answers

You could have just read the code FWIW - Django is open source. But anyway:

  1. signals receivers are called sequentially
  2. in your second snippet you are not calling object_instance.method - you need to add the parens (and eventually pass the relevant arguments - in this case at least the sender) to actually call the method.

To make a long story short : signals are mainly used to allow loose coupling between applications. If you want concurrent execution, you either have to use threads or subprocesses (which might not be safe depending on the execution environment) or go for something like celery.

like image 195
bruno desthuilliers Avatar answered Sep 30 '22 16:09

bruno desthuilliers