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.
问问题
277 次
2 回答
1
是的。为了回答您的问题更容易的部分,解决方案是return
在您的pycurl.WRITE_FUNCTION
.
我项目中的一个示例演示了如何实际断开理论上永无止境的 HTTP GET 请求(流)
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
于 2013-07-17T15:29:40.230 回答
1
- 是的,您可以使用回调查看PyCurl Doc中的那些示例
- 来自 libcurl 的许多 C 示例非常有用LibCurl
您可以轻松地在 python 中使用这些选项
于 2013-10-30T21:07:02.920 回答