首先必须要感谢一下辉哥的书, 先就这么称呼吧,哈哈.
感谢把我带入flask的大门,非常感谢.
最近碰到个问题, 我使用了flask-socketio, 使用gunicorn这个部署的flask.
后台使用emit发送消息的时候, 前端有时候能接到消息,有时候不能收到消息.
经过调试输入current_app的id值,结果这个值在不断的变化.
只有当前current_app是与websocketio建立连接的app时,发送消息才会成功.
以单个进程方式启动此时就没有问题了. 但是我想以多个进程方式运行,我现在还不知道该怎么处理.
希望碰到过这方面问题的朋友指点一二, 不胜感激.
3个进程启动输出信息如下:
gunicorn -w 3 --thread 3 --log-level=DEBUG --worker-class eventlet app:app
[2019-04-04 10:08:29 +0800] [109171] [DEBUG] POST /start_game
'start_game(), current_app: 140032880716752'
[2019-04-04 10:08:29 +0800] [109171] [DEBUG] Closing connection.
[2019-04-04 10:08:30 +0800] [109169] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880712368'
[2019-04-04 10:08:30 +0800] [109169] [DEBUG] Closing connection.
[2019-04-04 10:08:32 +0800] [109169] [DEBUG] POST /start_game
'start_game(), current_app: 140032880712368'
[2019-04-04 10:08:32 +0800] [109169] [DEBUG] Closing connection.
[2019-04-04 10:08:33 +0800] [109173] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880717040'
[2019-04-04 10:08:33 +0800] [109173] [DEBUG] Closing connection.
[2019-04-04 10:08:35 +0800] [109173] [DEBUG] POST /start_game
'start_game(), current_app: 140032880717040'
[2019-04-04 10:08:35 +0800] [109173] [DEBUG] Closing connection.
[2019-04-04 10:08:36 +0800] [109169] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880712368'
[2019-04-04 10:08:36 +0800] [109169] [DEBUG] Closing connection.
[2019-04-04 10:08:37 +0800] [109173] [DEBUG] POST /start_game
'start_game(), current_app: 140032880717040'
[2019-04-04 10:08:37 +0800] [109173] [DEBUG] Closing connection.
[2019-04-04 10:08:37 +0800] [109169] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880712368'
[2019-04-04 10:08:37 +0800] [109169] [DEBUG] Closing connection.
[2019-04-04 10:08:39 +0800] [109169] [DEBUG] POST /start_game
'start_game(), current_app: 140032880712368'
[2019-04-04 10:08:39 +0800] [109169] [DEBUG] Closing connection.
[2019-04-04 10:08:39 +0800] [109173] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880717040'
[2019-04-04 10:08:39 +0800] [109173] [DEBUG] Closing connection.
[2019-04-04 10:08:41 +0800] [109171] [DEBUG] POST /start_game
'start_game(), current_app: 140032880716752'
[2019-04-04 10:08:41 +0800] [109171] [DEBUG] Closing connection.
[2019-04-04 10:08:41 +0800] [109171] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 140032880716752'
[2019-04-04 10:08:41 +0800] [109171] [DEBUG] Closing connection.
单个进程启动输出信息如下
gunicorn -w 1 --thread 3 --log-level=DEBUG --worker-class eventlet app:app
[2019-04-04 10:10:59 +0800] [109420] [DEBUG] POST /start_game
'start_game(), current_app: 139984677481136'
[2019-04-04 10:10:59 +0800] [109420] [DEBUG] Closing connection.
[2019-04-04 10:10:59 +0800] [109420] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 139984677481136'
[2019-04-04 10:10:59 +0800] [109420] [DEBUG] Closing connection.
[2019-04-04 10:11:00 +0800] [109420] [DEBUG] POST /start_game
'start_game(), current_app: 139984677481136'
[2019-04-04 10:11:00 +0800] [109420] [DEBUG] Closing connection.
[2019-04-04 10:11:01 +0800] [109420] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 139984677481136'
[2019-04-04 10:11:01 +0800] [109420] [DEBUG] Closing connection.
[2019-04-04 10:11:01 +0800] [109420] [DEBUG] POST /start_game
'start_game(), current_app: 139984677481136'
[2019-04-04 10:11:01 +0800] [109420] [DEBUG] Closing connection.
[2019-04-04 10:11:02 +0800] [109420] [DEBUG] POST /report_start_game
'report_start_game(), current_app: 139984677481136'
[2019-04-04 10:11:02 +0800] [109420] [DEBUG] Closing connection.