Reputation: 496
I'm writing a python code to download files using pycurl
.
Is there any possibility to inform my program to disconnect the connection?
I mean that while the code is running, I want to disconnect the connection whenever I want.
(e.g. by clicking on a button and invoking a function). It can be used to pause the download.
Upvotes: 1
Views: 367
Reputation: 5220
Ah yes. To answer your question's easier part, the solution's to perform a "malicious" return
statement in your pycurl.WRITE_FUNCTION
.
An example here in my project demonstrates how to actually disconnect a theoretically never-ending HTTP GET request (streaming)
def _on_data_receive(self, data):
self.buffer += data
if data.endswith('\r\n'): # or any valid chunk delimiter
# Do something about self.buffer
print self.buffer
if True: # some valid condition to disconnect
return -1 # the way to stop the stream, would raise pycurl.error
Upvotes: 1
Reputation:
Upvotes: 1