curl-and-python

How to cancel a download?

From: Víctor Torres Ortiz <vito.ubb_at_gmail.com>
Date: Sat, 21 Feb 2009 22:23:58 -0300

Hello list,

I am working with pycurl, and would like to cancel a download (for
example, with a clic button event).

I start a download with this:

def button_download_clicked(self, widget):
        ...
        self.D = Download(url, file, self.progress)
        self.D.start()

and this is the Download class:

class Download(threading.Thread):
        def __init__(self, url, target_file, progress):
                threading.Thread.__init__(self)
                self.target_file = target_file
                self.progress = progress
                self.curl = pycurl.Curl()
                self.curl.setopt(pycurl.URL, url)
                self.curl.setopt(pycurl.WRITEDATA, self.target_file)
                self.curl.setopt(pycurl.FOLLOWLOCATION, 1)
                self.curl.setopt(pycurl.NOPROGRESS, 0)
                self.curl.setopt(pycurl.PROGRESSFUNCTION, self.progress)
                self.curl.setopt(pycurl.MAXREDIRS, 5)
                self.curl.setopt(pycurl.NOSIGNAL, 1)
                self.curl.setopt(pycurl.RESUME_FROM,
os.stat(target_file.name).st_size)

        def run(self):
                self.curl.perform()
                self.curl.close()
                self.target_file.close()
                self.progress(1.0, 1.0, 0, 0)

There is something like self.curl.stop() ?

can anyone help me, plis?

PD: this is my first mail, and I speaking Spanish :-D

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2009-02-22