2017-08-04 2 views
1

私は20秒にガンコンタイムアウトを設定する既存のフラスコの安らかなアプリでwebsocketをサポートしようとしています。私はフラスコソケット拡張を使用することにしました。フラスコソケットを使用しているときのワーカーのタイムアウト

websocket接続が通常のhttpリクエストとして扱われるので、レスポンスutilを返すことが期待されます。

私は、次のコードを追加し、geventwebsocket.gunicorn.workers.GeventWebSocketWorker

sockets = Sockets(app) 
@sockets.route('/log') 
def test_connect(socket): 
    while not socket.closed: 
     import time 
     time.sleep(2) 
     socket.send("heart beating") 

どのように私はこのような状況を処理するにgunicornのworker_classを変えましたか?アドバイスありがとう。

出力を追加します。

Traceback (most recent call last): 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/gevent/pywsgi.py", line 508, in handle_one_response 
    self.run_application() 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/geventwebsocket/handler.py", line 75, in run_application 
    self.run_websocket() 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/geventwebsocket/handler.py", line 52, in run_websocket 
    list(self.application(self.environ, lambda s, h, e=None: [])) 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/zeus_core/wsgi/wsgi.py", line 332, in __call__ 
    return self.app(environ, start_response) 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__ 
    return self.wsgi_app(environ, start_response) 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/flask_sockets.py", line 45, in __call__ 
    handler(environment, **values) 
File "./modulepub/app.py", line 49, in test_connect 
    time.sleep(2) 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/gevent/hub.py", line 75, in sleep 
    hub.wait(loop.timer(seconds, ref=ref)) 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/gevent/hub.py", line 341, in wait 
    result = waiter.get() 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/gevent/hub.py", line 568, in get 
    return self.hub.switch() 
File "/Users/bayi/Documents/dev/python/venvs/modulepub/lib/python2.7/site-packages/gevent/hub.py", line 331, in switch 
    return greenlet.switch(self) 
Timeout: 20 seconds 
+0

端末出力(スタックトレース)を追加してください – Nabin

+0

@Nabin traceback added – bayi

答えて

0

は、タイムアウトは我々が使用するフレームワークによって設定されていることがわかりました。これは、各APIコールのタイムアウトを設定するためにフラスコのアプリケーションにミドルウェアを追加します。タイムアウトの設定を変更することでこれを解決できます。

関連する問題