Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用烧瓶套接字时工作线程超时_Python_Flask_Websocket_Flask Sockets - Fatal编程技术网

Python 使用烧瓶套接字时工作线程超时

Python 使用烧瓶套接字时工作线程超时,python,flask,websocket,flask-sockets,Python,Flask,Websocket,Flask Sockets,我试图在现有的flask restful应用程序中支持websocket,该应用程序将gunicorn超时设置为20秒。我决定使用flask sockets扩展,事情进展顺利,但greentlet会在20秒后超时 我假设websocket连接被视为一个正常的http请求,因此它应该在greenlet超时之前返回一个响应 我添加了以下代码,并将gunicorn worker_类更改为geventwebsocket.gunicorn.workers.GeventWebSocketWorker soc

我试图在现有的flask restful应用程序中支持websocket,该应用程序将gunicorn超时设置为20秒。我决定使用flask sockets扩展,事情进展顺利,但greentlet会在20秒后超时

我假设websocket连接被视为一个正常的http请求,因此它应该在greenlet超时之前返回一个响应

我添加了以下代码,并将gunicorn worker_类更改为
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

发现超时是由我们使用的框架设置的。它向flask应用程序添加了一个中间件,为每个api调用设置超时。更改超时配置可以解决这个问题。

发现超时是由我们使用的框架设置的。它向flask应用程序添加了一个中间件,为每个api调用设置超时。更改超时配置可以解决此问题。

请添加终端输出(stacktrace)@Nabin traceback added请添加终端输出(stacktrace)@Nabin traceback added