Limit download (or upload) rate in PyCurl

abril 22nd, 2008 § 2 comments

I'm used to work with curl in other programming languages like php or perl, so pycurl became my first choice in python url access libraries .

Pycurl it's not a native module like urllib2, instead is a wrapper for the C library libcurl, it is not as fancy as native python modules are, but is extremely fast and you have lots of features. Also if you want to find documentation about how to use Pycurl is better to look at libcurl's documentation and examples.

And so I did. In libcurl documentation I found which options i could set for libcurl API to limit download bandwidth usage, MAX_RECV_SPEED_LARGE. Note that options in Pycurl are the same that in libcurl without the prefix CURLOPT.

Here is a simple example of how to limit download a file with a 10KB limit rate:

PYTHON:
  1. import pycurl
  2.  
  3. c = pycurl.Curl()
  4. c.setopt(c.URL, "http://python.org/ftp/python/2.5.2/Python-2.5.2.tgz")
  5. c.setopt(c.MAX_RECV_SPEED_LARGE, 10000)
  6. c.setopt(c.WRITEDATA, file("python-2.5.2.tar.gz","w"))
  7. c.perform()

And this is my story :P

Tagged , , , ,

§ 2 Responses to Limit download (or upload) rate in PyCurl"

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *


ocho × 1 =

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation

What's this?

You are currently reading Limit download (or upload) rate in PyCurl at arde en el infierno.

meta