6

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

1 Answer 1

2

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.

1
  • Thanks! That was the solution I arrived at as well. When I explored the code for the send() method, I found that Django literally just for loops over the receivers sequentially. Celery seems to be the solution for parallel execution, specifically subtask groups.
    – flimsy
    Mar 19, 2013 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.