2013-04-05 7 views
3

나는이 오류 받고 있어요 : 다음 코드를 실행하는 동안파이썬 HTTP 599 : 연결이 종료 (토네이도)

HTTP 599: Connection closed [E 130405 11:43:14 web:1031] Uncaught exception GET /networks/1/sensors/1/alarm (127.0.0.1)

을 : 클래스에서

from tornado.stack_context import ExceptionStackContext 

def handle_exc(*args): 
print('Exception occured') 
return True 

@tornado.gen.engine 
def check_status_changes(netid, sensid): 

    como_url = "".join(['http://131.114.52:44444/ztc?netid=', str(netid), '&sensid=', str(sensid), '&start=-5s&end=-1s']) 

    http_client = AsyncHTTPClient() 
    response = yield tornado.gen.Task(http_client.fetch, como_url) 

    if response.error is not None: 
      print("Terzo") 
      print response.error 
      with ExceptionStackContext(handle_exc): 
       response.rethrow() 
    else: 
     print('Handle request') 

    for line in response.body.split("\n"): 
       if line != "": 
        #net = int(line.split(" ")[1]) 
        #sens = int(line.split(" ")[2]) 
        #stype = int(line.split(" ")[3]) 
        value = int(line.split(" ")[4]) 
        print value 
        yield value 
        return 


class AlarmHandler(BaseHandler): 
    @tornado.web.authenticated 
    @tornado.web.asynchronous 
    @tornado.gen.engine 
    def get(self, netid, sensid): 
     self.lock_tables("read", ['devices']) 
     status = self.db.get("SELECT status from devices \ 
          WHERE id=%s AND network_id=%s", sensid, netid) 
     print("Primo") 
     print status 

     try: 
      periodic = tornado.ioloop.PeriodicCallback(check_status_changes(netid, sensid), 5000) 
      value = periodic.start() 
      print("Secondo") 
      print value 
     except: 
      print("Quarto") 
      periodic.stop() 
      self.finish() 
      return 
     if value != status['status']: 

      self.lock_tables("write", ['devices']) 
      self.db.execute("UPDATE devices SET status=%s \ 
          WHERE id=%s AND network_id=%s", value, netid, sensid) 
      self.unlock_tables() 
      self.notice("Status changed") 

AlarmHandlercheck_status_changes라는 정기적 인 루틴이 . 이 함수에서는 response.error가있을 때 제목의 오류를 얻습니다.

클래스로 돌아가서 상황을 관리하기 위해 오류 조건을 설정하려면 어떻게해야합니까? 고맙습니다. 나는 토네이도의 화면을 할 경우

기타 정보

, 나는이를 참조하십시오

Primo

{'status': None}

Secondo

None

Terzo

HTTP 599: Connection closed

Exception occured

그래서, 나는 예외가 rethtow되기 전에 프로그램이 연결을 닫을 생각! 당신은 예외를 발생하는

File "./wsn.py", line 226, in check_status_changes for line in response.body.split("\n"): AttributeError: 'NoneType' object has no attribute 'split'

답변

0

:

if response.error: 
     print("Terzo") 
     print response.error 
     raise Exception(response.error) 
     return 

이는 Uncaught Exception 될 것

하고 HTML consolle에

는이 오류를 참조하십시오. 예외를 발생시키지 않고 예외를 처리하려면이 코드를 작성해야합니다. 예 : 오류 메시지를 기록하고 데이터베이스 갱신을 중단하십시오.

+1

좋아, MattH이 솔루션을 사용해 보았습니다. http://stackoverflow.com/a/7623570/1353274 파이썬 채팅에서 저를 소개해 드리겠습니다. 나는 시도했다. 그러나 그것이 같은 오류 다. 인터넷에서 검색 나는 오래된 Tornado 버전에서 유사한 버그가 있다는 것을 알았다. 내 문제 일 수 있는가? 토네이도 버전을 어떻게 얻을 수 있습니까? 그러나 귀하의 솔루션으로 질문을 편집합니다. – sharkbait

관련 문제