is it possible to easily cap the kbps when using urllib2? If it is, any code examples or resources you could direct me to would be greatly appreciated.
is it possible to easily cap the kbps when using urllib2 ? If it
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No related questions found
There is the
urlretrieve(url, filename=None, reporthook=None, data=None)function in theurllibmodule. If you implement thereporthook-function/object as either a token bucket, or a leaky bucket, you have your global rate-limit.EDIT: Upon closer examination I see that it isn’t as easy to do global rate-limit with
reporthookas I thought.reporthookis only given the downloaded amount and the total size, which on their own isn’t enough to information to use with the token-bucket. One way to get around it is by storing the last downloaded amount in each rate-limiter, but use a global token-bucket.EDIT 2: Combined both codes into one example.