1
我試圖在現有的燒瓶平靜應用中將websocket設置爲20秒。我決定使用瓶子插槽擴展,除了20秒後greentlet會超時之外,事情進展順利。使用燒瓶插座時的工作者超時
我假設websocket連接被視爲一個普通的http請求,所以它期望返回一個響應util greenlet超時。
添加以下代碼,改變了gunicorn worker_class到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")
我應該如何處理這種情況?感謝您的任何建議。
外接輸出:
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
請添加您的終端輸出(stacktrace) – Nabin
@Nabin traceback added – bayi