1

I am trying to do some logging in Django (mod_wsgi) of a view. I however want to do this so that the client is not held up similar to the perlcleanuphandler phase available in mod_perl. Notice the line "It is used to execute some code immediately after the request has been served (the client went away)". This is exactly what I want.

I want to client to be serviced and then I want to do the logging. Is there a good insertion point for the code in mod_wsgi or Django ? I looked into suggestions here and here. However, in both cases when I put a simple time.sleep(10) and do a curl/wget on the url, the curl doesn't return for 10 secs.

I even tried to put the time.sleep in __del__ method in the HttpResponse Object as suggested in one of the comments, but still no dice.

I am aware that I can probably put the logging data onto a queue and do some backgroud processing to store the logs, but I would like to avoid that approach if there is an other simpler/easier approach.

Any suggestions ?

Community
  • 1
  • 1
Viral Shah
  • 71
  • 2
  • Have you tried the [request_finished](https://docs.djangoproject.com/en/dev/ref/signals/#django.core.signals.request_finished) signal? Here's [an example](http://stackoverflow.com/q/2368352/520779) of how to use it. (though I haven't tried it myself, dunno if it will suffer the same problem if you try `time.sleep`) – mgibsonbr Aug 20 '12 at 19:06

1 Answers1

0

See documentation at:

http://code.google.com/p/modwsgi/wiki/RegisteringCleanupCode

for a WSGI specific (not mod_wsgi specific) way.

Django as pointed out by others may have its own ways of doing things as well, although whether it is fired after all the response content is written back to the client I don't know.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134