2011-05-16 4 views
0

스레드를 사용하는 pywebsocket (http://code.google.com/p/pywebsocket)과 함께 제공되는 독립 실행 형 서버의 처리기를 작성하려면 id를 사용하십시오. 그래서 ... 어떤 코멘트없이 을스레드를 사용하는 python HTTPServer의 처리자

class _Stub(threading.Thread): 
def __init__ (self): 
    threading.Thread.__init__(self) 
    self._test = 0 

def run(self): 
    while True: 
     time.sleep(5) 
     self._test = self._test + 1 

하지만 서버가 충돌 :

def web_socket_transfer_data(request): 
    while True: 
    line = request.ws_stream.receive_message() 
    if line is None: 
     return 
    request.ws_stream.send_message(line) 
    if line == _GOODBYE_MESSAGE: 
     return 

필자가 스레드를 추가하려고 : 핸들러 pywebsocket에 나오는 예제 는 기능을 가진 단지 파일입니다 어떻게 된거 야?

감사합니다.

답변

0

독립 실행 형 서버가 비 차단 메시지를 수신하도록 설계되지 않았습니다. msgutil.py에있는 클래스 "MessageReceiver"의 문서 (적어도 SSL을 사용하지 않을 때) :

이 클래스는 클라이언트로부터 메시지를 수신합니다.

This class provides three ways to receive messages: blocking, 
non-blocking, and via callback. Callback has the highest precedence. 

Note: This class should not be used with the standalone server for wss 
because pyOpenSSL used by the server raises a fatal error if the socket 
is accessed from multiple threads. 
관련 문제