简体   繁体   中英

Django Signal vs Python Threading

Its hard to explain what I am trying to achieve. Please have the patience to go through this. And let me know if you have any questions.

Say I have a Django project with two applications which I would like to have them coupled loosely. One of the application is 'Jobs' and other is 'Notifications'.

Now I want to create notifications when the Job instance is updated. So, I was thinking of using Django Signals. But some of the reservations I have are:

  1. If I use the build-in signals like post_save. I could validate the conditions on job instance and generate notification(which is good). But the problem comes when, in the same view logic I call the save method on job instance multiple times. This would generate notifications multiple times. Else, I use the home made signals I would be required to call it manually which is not good for loose coupling.
  2. Moreover, the signals are not asynchronous so, I would have to wait for the notification generation to complete before I can proceed.

Can anyone please suggest a good implementation strategy using Signals. One solution I was looking into was Python Threading which seems to take care of the asynchronous problem. But are there any other consequences of using Threading.

I would suggest you to use django-celery with RabbitMQ. You can add the notifications thing in the tasks of celery and have your view start the task queque. Have a look....I hope it will be helpful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM