Bandwidth throttling in Python

前端 未结 2 1973
天命终不由人
天命终不由人 2021-01-31 12:43

What libraries out there let you control the download speed of network requests (http in particular). I don\'t see anything built-in in urllib2 (nor in (Py)Qt which I intend on

2条回答
  •  花落未央
    2021-01-31 12:53

    urllib2 doesn't offer a way to do this, so you'd have to extend some of the classes it uses and implement rate limiting yourself. You might want to look at this question. If you decide to write a limiter, read up on the token bucket and leaky bucket algorithms.

    Alternatively, you could use pycurl along with the CURLOPTMAXRECVSPEEDLARGE option.

    EDIT: The urlgrabber package appears to support throttling as well, and is probably easier to understand than pycurl.

    If you prefer to program using an event loop model, there's the Twisted approach, which has already been mentioned in another answer.

提交回复
热议问题