Python, gevent, urllib2.urlopen.read(), download accelerator

ぃ、小莉子 提交于 2019-12-01 08:41:16

You're trying to read a response to a single request from different greenlets.

If you'd like to download the same file using several concurrent connections then you could use Range http header if the server supports it (you get 206 status instead of 200 for the request with Range header). See HTTPRangeHandler.

the argument to read is a number of bytes, not an offset.

It seems gevent will let you call urllib asynchronously, but not let you access the same resource from multiple greenlets.

Furthermore, since it is using wait_read, the effect will still be a synchronous, sequential read from the file (The complete opposite of what you wanted to achieve).

I'd suggest you might need to go lower than, or use a different library from, urllib2.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!