Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why there is no response_finished signal in Django?

I am trying to implement some kind of background task queue in Django, because Celery is too huge & complex, then it occured to me that, there is already a signal called request_finished

https://docs.djangoproject.com/en/dev/ref/signals/#django.core.signals.request_finished

But why Django do not have a signal called response_finished ?

Django may be synchronous, but I can do some post-response data processing and saving tasks, it only taks few more steps.

Is hacking a way to do some post-response work possible in Django?

TIA

like image 627
est Avatar asked Jan 26 '26 14:01

est


2 Answers

You can write your own middleware (specifically using process_response) if you need to perform tasks after the response has been assembled. There would be no point in having a signal handler after the response is 'finished' as by that stage, you have executed your view and rendered your template.

like image 178
Timmy O'Mahony Avatar answered Jan 29 '26 04:01

Timmy O'Mahony


since no one answers this, I have some conclusions myself

https://groups.google.com/d/topic/python-web-sig/OEahWtsPwq4/discussion

It's basically a wsgi design behavior. Wsgi will not care what happens after respons iterator stops.

like image 37
est Avatar answered Jan 29 '26 03:01

est