On 6/6/06, Ivan Sagalaev <[EMAIL PROTECTED]> wrote: > Ah... This is interesting :-). A web server will know that a client has > been disconnected only when it will try to send it something. So if you > have a long working view you can't know if it works for nothing until it > finishes. > > It's good when you can do calculations and push results to the client > iteratively. Then you can create an iterator and pass it to a > HttpResponse. It then will call your code until it's done or an error > writing data to the client occured. It looks like this: > > def long_process(): > while not done: > data_chunk = calculate_data_chunk() > yield data_chunk > > > def some_view(request): > return HttpResponse(long_process()) > > P.S. In mod_python you can actually catch the write error in Dango's > core/handlers/modpython.py because the loop iterating over response's > iterator is there in 'populate_apache_response'. However in general case > (WSGI) it's outside of Django and is not accessible.
Oh wow, you can pass an iterable to HttpResponse? I never noticed that before! If the write fails before all the iterations are done though, I guess I have no way to generically catch that, to do any kind of cleanup I might need? Jay P. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---