To defeat urllib2's internal buffering, you can do:
import socket
socket._fileobject.default_bufsize = 0
because it is the actual socket._fileobjectone that buffers under it. In any case, the data will not be lost, but with default buffering (8192 bytes at a time), the data may turn out to be too interleaved for real-time streaming (completely removing buffering may hurt performance, but you can try smaller chunks).
For Twisted, see twisted.web2.stream and many links from them.
source
share