curl-and-python

Re: "Previous alarm fired off!" then Segmentation fault

From: 李万俊 <biduan_at_gmail.com>
Date: Fri, 20 Jun 2008 13:47:38 +0800

supplementary,
when i remove the :

                self.__curl.setopt(pycurl.TIMEOUT, 300)
                self.__curl.setopt(pycurl.CONNECTTIMEOUT, 60)

from class ,error "Previous alarm fired off!" is not display,but my program
would random down ,tell me that there is "Segmentation fault" and generate a
python core dump.

2008/6/20 <biduan_at_gmail.com>:

> Hi,
> As want to re-use one connection for a same host,
> I write a simple a class ,which wrapped the pycurl.
>
> however,when the code run ,there is a error "Previous alarm fired off!"
>
> i don't known is i call pycurl in a wrong or some else case this error.
> Is anybody give me some advice?
>
> my code is:
> ====================================================
> class reusecrawler:
> def __init__(self):
> self.__buf=StringIO.StringIO()
> self.__curl = pycurl.Curl()
> self.__response=""
> self.__curl.setopt(pycurl.FOLLOWLOCATION, 1)
> self.__curl.setopt(pycurl.MAXREDIRS, 5)
> #self.__curl.setopt(pycurl.NOSIGNAL, 1)
> self.__curl.setopt(pycurl.WRITEFUNCTION,self.__response_callback)
> self.__curl.setopt(pycurl.USERAGENT,"Mozilla/4.0 (compatible;")
> #self.errorCode=0
> def get(self,url):
> self.__response=""
> self.__curl.setopt(pycurl.TIMEOUT, 300)
> self.__curl.setopt(pycurl.CONNECTTIMEOUT, 60)
> self.__curl.setopt(pycurl.URL, url)
> log.debug("Crawle url:%s"%url <http://%25s%22%25url/>)
> self.__curl.perform()
> self.httpCode=self.__curl.getinfo(pycurl.HTTP_CODE)
>
> self.downSpeed=(self.__curl.getinfo(pycurl.SPEED_DOWNLOAD)*8)/1000
> #curl.close()
> self.content=self.__response
> self.__buf.close()
>
> def close(self):
> self.__curl.close()
>
> def __response_callback(self,body):
> self.__response +=body
>
> there would be a Thread class such as:
>
>
> class A(threading.Thread):
> ..........
> def run(self):
> try:
> #batch url has same format such a http:
> www.xxx.com/xx.html
> for url in self.batchUrl:
> self.myreusecrawler.get(url)
> .......
> except:
> import traceback
> traceback.print_exc()
> =========================================================
>
> Best regards
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2008-06-20