while 1:
ret, num_handles = self.m.perform()
if ret == pycurl.E_CALL_MULTI_PERFORM: continue
if num_handles > 0:
ret = self.m.select(1.0)
if ret == -1: continue
else:
self.close()
break
print ‘哈哈’
def write(self,buff):
def header(self,buff):
print buff
print ‘ ‘
def Init(self):
for i in range(10):
c = pycurl.Curl()
c.setopt(pycurl.URL, str(‘
http://cool.joojoe.com/w.html’
;)) #强制转为str 如果是其他字符会报错
c.setopt(pycurl.CONNECTTIMEOUT, 10)#链接超时
c.setopt(pycurl.WRITEFUNCTION, self.write)#写(下载)回传函数,传递一个写指针供外部操作, 一次回调内容大小在
c.setopt(pycurl.HEADERFUNCTION, self.header)#只接收头数据
c.setopt(pycurl.TIMEOUT, 10)#下载超时
c.setopt(pycurl.PROXY, ‘211.90.10.121:80’)# 使用代理
self.m.handles.append(c)
self.m.add_handle(c)
def close(self):
print ‘close CurlMulti’
for c in self.m.handles:
c.close()
self.m.close()
if __name__ == ‘__main__’:
c = curl()
c.Init()
c.exe()