1

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.

4

2 回答 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
于 2013-10-30T21:07:02.920 回答