将Flask-SockerIO设置为在Gunicorn Server中运行

时间:2013-12-24 18:44:23

标签: flask gevent gunicorn socket.io gevent-socketio

我尝试运行SocketIO服务器在Ubuntu OS中的Gunicorn中运行。

GEVENT
GEVENT-socketio
gunicorn

run.py

from views import app
from gevent import monkey
from socketio.server import SocketIOServer
import werkzeug.serving

monkey.patch_all()
PORT = 5000

@werkzeug.serving.run_with_reloader
def runServer()
    print 'Listening on http://127.0.0.1:%s and on port 10843 (flash policy server)' % PORT
    SocketIOServer(('', PORT), app, resource="socket.io").serve_forever()

if __name__ == '__main__':
    runServer()

使用的命令 -

gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker run:app

连接似乎经常被丢弃和重新连接 日志 -

2013-12-24 22:40:59 [3331] [INFO] Starting gunicorn 0.13.4
2013-12-24 22:40:59 [3331] [INFO] Listening at: http://127.0.0.1:8000 (3331)
2013-12-24 22:40:59 [3331] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
2013-12-24 22:40:59 [3334] [INFO] Booting worker with pid: 3334
2013-12-24 22:41:01 [3339] [INFO] Starting gunicorn 0.13.4
2013-12-24 22:41:01 [3339] [ERROR] Connection in use: ('127.0.0.1', 8000)
2013-12-24 22:41:01 [3339] [ERROR] Retrying in 1 second.
2013-12-24 22:41:02 [3339] [ERROR] Connection in use: ('127.0.0.1', 8000)
2013-12-24 22:41:02 [3339] [ERROR] Retrying in 1 second.
2013-12-24 22:41:03 [3339] [ERROR] Connection in use: ('127.0.0.1', 8000)
2013-12-24 22:41:03 [3339] [ERROR] Retrying in 1 second.
2013-12-24 22:41:04 [3339] [ERROR] Connection in use: ('127.0.0.1', 8000)
2013-12-24 22:41:04 [3339] [ERROR] Retrying in 1 second.

1 个答案:

答案 0 :(得分:0)

您可以对此行@ werkzeug.serving.run_with_reloader发表评论,它应该有效。