I have a curl request in python which outputs a large amount of data to a writefunction (CURLOPT_WRITEFUNCTION). I want to be able to cancel the curl request from the writefunction if a certain condition is met. I've tried using ch.close(), but that errors saying that it cant close a request while its being performed. Any other way to get it to stop from a writefunction? Heres my code:
self.ch = pycurl.Curl()
self.ch.setopt(pycurl.URL, file_url)
self.ch.setopt(pycurl.CONNECTTIMEOUT, 60)
self.ch.setopt(pycurl.WRITEFUNCTION, self.WriteWrapper)
self.ch.setopt(pycurl.HEADERFUNCTION, self.ParseHeaders)
self.ch.setopt(pycurl.FOLLOWLOCATION, True)
self.ch.setopt(pycurl.COOKIE, cookies[file_host])
self.ch.setopt(pycurl.HTTPHEADER, self.headers_received)
self.ch.perform()
self.ch.close()
def do_POST(self):
return self.do_GET()
def WriteWrapper(self, data):
if self.do_curl_request:
try:
return self.wfile.write(data)
except:
self.ch.close() # This doesn't work :(