> > I need to do some cleanup after sending a response to the client. That > > means I want to send response without returning a response object. > > Something like- > > > def handler(request): > > # ... > > resp = HttpResponse(data) > > # send response in some way (?) > > # clean up, log, etc.. > > > I know its unusual to do this, but is there a way to achieve it? If > > not directly, then a way to setup the cleanup code to run after the > > response has been sent will also do. > > What sort of things do you need to do that can't be done before sending > back the response? Most of the things I can think of (such as the time > taken to send the response) are out of scope for Django, since it lives > at a layer below the stuff that actually interacts with the webserver.
Thanks for the reply Malcolm. My actual requirement is to convert a video file from one format to another and send the output as a stream, here is an example that uses ffmpeg to do the conversion. The handler captures the result at stdout and sends it by wrapping in a FileWrapper. def handler(request): # ... cmd = "ffmpeg -i %s -f flv -" % filename subp = subprocess.Popen(cmd, stdout=subprocess.PIPE) result = subp.stdout wrapper = FileWrapper(result) response = HttpResponse(wrapper) # need to wait till the response has actually been sent .. if subp.wait() != 0: # something went wrong, log it.. I want to stream as soon as possible without loading the entire result in memory and preferably without having to save the result to disk. I have ommitted the code for setting headers, etc. for clarity. Any ideas or suggestions on how to go here? Ram --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---