pycurl 지속 연결에서 연결 끊김 여부는 어디에서 확인해야합니까?연결 해제 지속성 컬 연결
내 스크립트의 어느 부분에서 연결이 끊어 지거나 시간이 초과되었거나 오류가 발생했지만 스크립트는 계속 열려 있습니다. 스크립트를 다시 시작할 수 있도록 문제를 감지해야합니다.
우리는 (소셜 미디어 데이터 공급자)
내 코드가 여기에있다 gnip에 연결되어 내가 libcurl에 대한 옵션을 통해 읽고 한 https://gist.github.com/3353033
내가 PHP를 curl_setopts의 문서를 읽어 또한 때문에 libcurl을 활용하십시오.
class Client:
time_start = time.time()
content = ""
def __init__(self,options):
self.options = options
self.buffer = ""
self.conn = pycurl.Curl()
self.conn.setopt(pycurl.USERPWD, "%s:%s" % (USER, PASS))
self.conn.setopt(pycurl.ENCODING,'gzip')
self.conn.setopt(pycurl.URL, STREAM_URL)
self.conn.setopt(pycurl.WRITEFUNCTION, self.on_receive)
self.conn.setopt(pycurl.FOLLOWLOCATION,1)
self.conn.setopt(pycurl.MAXREDIRS, 5)
self.conn.setopt(pycurl.COOKIEFILE,"cookie.txt")
try:
self.conn.perform()
except Exception,e:
print e.message
def on_receive(self, data):
self.buffer += data
if data.endswith("\r\n") and self.buffer.strip():
if(self.triggered()):
if(len(self.buffer) != 0):
try:
SaveThread(self.buffer).start()
except Exception, e:
print "something i commented would have told you there was an error"
system.exit(1)
self.buffer = ""
def triggered(self):
# First trigger based on size then based on time..
if (len(self.buffer) > SAVE_FILE_LENGTH):
return True
time_end = time.time()
if (((time_end - self.time_start) > ROLL_DURATION)): #for the time frame
self.time_start=time.time()
return True
return False
편집 : 나는 sys.exit(1)
바로해야 위의 코드 system.exit(1)
에서 요점
요점이 올바로 들여 쓰기되어 있지 않습니다. 나는 또한 여기에 소스를 게시하는 것이 좋습니다. – stderr
@MikeSteder 나는 그 요지를 고쳤다 고 믿고 여기서 그것을 복사했다. 감사! – Jake