Cool. That is a clever way to subvert (I don't mean this negatively) the response generation. I do have a couple of comments:
1) It relies on the response being sent to the client as it is generated and not buffered by the server. That is clearly working for you and I don't know the internals of the different web servers to know if any would break this. I suspect this will work with all servers so nice trick. 2) I would be worried by resources on the web server if you expect many connections of this type. In most servers that I have seen, each request is assigned to a thread from a pool and the thread is not freed up until the request is completed. Each of these requests will tie up a thread until it is completed (I think). This is likely to work well for a small number of simultaneous connections but if you had more simultaneous clients than threads in your pool, I would expect new requests to be blocked / delayed. If you only expect one or a small number of clients to use this request at one time then you are fine. If you want to scale this then I think that you may have a problem. I suggest testing this by setting up more simultaneous clients than your server has threads set in the pool. The test might be fiddly to set up and you could reconfigure the server to have fewer threads and add delays into the calculations to make it easier to test. This is the reason why I chose to build my own custom server for long- running requests but that causes a lot of extra work and possible bugs so I don't recommend it if there is any alternative. Cheers Ian On Jun 15, 8:45 pm, Christoph Siedentop <christophsieden...@gmail.com> wrote: > Hi Dmitry, hi Ian, > > thanks for the help. > > I got it to work. Here is what I am doing. > > Django gets a request for "/data.json". A view function is called. > This is my function: > > def data(request): > return HttpResponse(subsampling(), mimetype='application/javascript') > > subsampling() is an iterator, i.e. it yields data every once in while. > Look > at:http://docs.djangoproject.com/en/dev/ref/request-response/#passing-it... > > I am yielding simplejson.dumps(my_dict) + '\n' which is then received > by the client. The original request for data.json came from an ajax > function (using jQuery). At the beginning using 'beforeSend' I start a > function that takes the XmlHttpRequest.responseText and sees how much > data has arrived and appends that data to the already existing data. I > do this every 10ms and stop once the xmr.readyState indicates that the > connection was closed. > > I am quite satisfied with this result. It does not use much memory and > is much faster (and feels much faster) than before. > > I tested it under Chromium, Firefox and Konqueror. I will add some > additional functionality and make it a nice graphics module in the > late summer. Probably GPL'ed. It would be for people like me, who have > lots of data and want to make them available interactively. > > Regards, > Christoph > <<History snipped for brevity.>> -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.