After a lot of dead ends, I finally found the problem! The cause is the
switch to using CompatibleStreamingHttpResponse in the
django.views.static.server view. Previously, the view simply read the
whole file into memory and returned a regular HTTP response. The
StreamingHTTPResponse class uses the file iterator to return data, which
in turn returns one line per iteration. I'm not at all sure why, but
this seams to cause a problem when requesting many files at once (e.g.,
Chrome).
In order to verify that this was the problem, I solved the issue by
adding a *file_chunk_iterator *function (yields 1024 bytes per
iteration, rather than one line like the standard Python file iterator),
and changing the response in the serve view from this:
response = CompatibleStreamingHttpResponse(open(fullpath, 'rb'),
content_type=mimetype)
to this:
response =
CompatibleStreamingHttpResponse(file_chunk_iterator(open(fullpath,
'rb')), content_type=mimetype)
The iterator function looks like this:
def file_chunk_iterator(f, size=1024):
while True:
chunk = f.read(size)
if chunk:
yield chunk
else:
return
On 7/3/2013 5:39 PM, Nikolas Stevenson-Molnar wrote:
> I've just updated to Django 1.5 and am running into a problem when
> using Chrome with the Django devlopment server (and staticfiles). One
> particular page which loads a lot of static content /consistently/
> hangs in Chrome (works fine in Firefox). This seems similar to two
> resolved issues: https://code.djangoproject.com/ticket/16099 and
> https://code.djangoproject.com/ticket/18336. Except that I've waited
> several minutes and the resources haven't finished loading. I've
> increased request_queue_size as suggested in the second issue (first
> to 10, then 20, then 50) with no change.
>
> I'd chalk this up entirely as a Chrome problem, except that if I
> switch back to Django 1.4 (changing nothing else), everything goes
> back to working fine. So what changed about runserver in Django 1.5
> that might cause this? And more importantly, how do I get around it?
> I'm running everything on Windows 7 with Django 1.5.1 and the latest
> version of Chrome.
>
> Thanks,
> _Nik
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.