0

スレッドを使用する pywebsocket (http://code.google.com/p/pywebsocket) に付属するスタンドアロン サーバー用のハンドラーを作成したいと考えています。pywebsocket に付属する例では、ハンドラーは関数を含む単なるファイルです。

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

スレッドを追加しようとしました:

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

しかし、サーバーはコメントなしでクラッシュします...では、これはどのように行われますか?

ポインタをありがとう。

4

1 に答える 1

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.
于 2012-04-16T14:12:10.527 に答える