3

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

est
  • 11,429
  • 14
  • 70
  • 118
  • 2
    Is the data processing somehow dependent on the contents of the response? That seems highly unlikely. Why not launch a thread from inside the view? The task would still be asynchronous and it won't block the response. This answer may be more helpful - http://stackoverflow.com/a/11904222/420386 – Okal Otieno Sep 18 '12 at 10:54

2 Answers2

3

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.

Timmy O'Mahony
  • 53,000
  • 18
  • 155
  • 177
  • the point is I can use do some data processing after response in the context of the executed views. E.g. some remote db may be slow, execute that during view would cost extra time that hogs the reponse. – est Jul 11 '12 at 04:21
1

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.

est
  • 11,429
  • 14
  • 70
  • 118