【已解决】websocket启动出错:gunicorn.errors.HaltServer HaltServer App failed to load 4

折腾:

【已解决】flask中实现websocket

期间,

启动了websocket:

/Users/crifan/dev/dev_root/daryun/Projects/RunningFast/sourcecode/RunningFast-Server/runningfast/app.py

############################################################
# Flask-SocketIO
############################################################
from flask_socketio import SocketIO, emit
socketio = SocketIO(app)
@socketio.on(‘my event’, namespace=’/test’)
def test_message(message):
    emit(‘my response’, {‘data’: message[‘data’]})
@socketio.on(‘my broadcast event’, namespace=’/test’)
def test_message(message):
    emit(‘my response’, {‘data’: message[‘data’]}, broadcast=True)
@socketio.on(‘connect’, namespace=’/test’)
def test_connect():
    emit(‘my response’, {‘data’: ‘Connected’})
@socketio.on(‘disconnect’, namespace=’/test’)
def test_disconnect():
    print(‘Client disconnected’)

以及:

/Users/crifan/dev/dev_root/daryun/Projects/RunningFast/sourcecode/RunningFast-Server/run.py

# from runningfast.app import app
from runningfast.app import socketio
if __name__ == ‘__main__’:
    #app.run(debug=True)
    # app.run()
    socketio.run()

但是运行出错:

/Users/crifan/dev/dev_root/daryun/Projects/RunningFast/sourcecode/RunningFast-Server/logs/gunicorn.err

<div–<——————————————————————————
DEBUG in app [/root/RunningFast/staging/runningfast/app.py:79]:
app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7f0a9646aed0>, redis_store=<flask_redis.FlaskRedis object at 0x7f0a94ba6850>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f0a96405350>, socketio=<flask_socketio.SocketIO object at 0x7f0a964056d0>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:190]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

Failed to find application: ‘run’
[2016-10-27 17:48:08 +0000] [12774] [INFO] Worker exiting (pid: 12774)

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:190]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

Failed to find application: ‘run’
[2016-10-27 17:48:08 +0000] [12775] [INFO] Worker exiting (pid: 12775)

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:190]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:190]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

Failed to find application: ‘run’
[2016-10-27 17:48:08 +0000] [12776] [INFO] Worker exiting (pid: 12776)
Failed to find application: ‘run’
[2016-10-27 17:48:08 +0000] [12777] [INFO] Worker exiting (pid: 12777)
Traceback (most recent call last):
  File "/root/Envs/RunningFast/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
    super(Application, self).run()
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/arbiter.py", line 218, in run
    self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/arbiter.py", line 331, in halt
    self.stop()
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/arbiter.py", line 381, in stop
    time.sleep(0.1)
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/arbiter.py", line 231, in handle_chld
    self.reap_workers()
  File "/root/Envs/RunningFast/lib/python2.7/site-packages/gunicorn/arbiter.py", line 509, in reap_workers
    raise HaltServer(reason, self.APP_LOAD_ERROR)
gunicorn.errors.HaltServer: <HaltServer ‘App failed to load.’ 4>

但是Log中,好像又没有错误:

/Users/crifan/dev/dev_root/daryun/Projects/RunningFast/sourcecode/RunningFast-Server/logs/RunningFast.log

[2016-10-27 17:48:08,003 DEBUG app.py:79 <module>] app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7f0a963ebdd0>, redis_store=<flask_redis.FlaskRedis object at 0x7f0a94ba9750>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f0a96409250>, socketio=<flask_socketio.SocketIO object at 0x7f0a964095d0>
[2016-10-27 17:48:08,061 DEBUG app.py:79 <module>] app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7f0a963ebe50>, redis_store=<flask_redis.FlaskRedis object at 0x7f0a94ba97d0>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f0a964062d0>, socketio=<flask_socketio.SocketIO object at 0x7f0a96406650>
[2016-10-27 17:48:08,109 DEBUG app.py:79 <module>] app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7f0a96469f50>, redis_store=<flask_redis.FlaskRedis object at 0x7f0a94ba68d0>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f0a964053d0>, socketio=<flask_socketio.SocketIO object at 0x7f0a96405750>
[2016-10-27 17:48:08,131 DEBUG app.py:79 <module>] app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7f0a9646aed0>, redis_store=<flask_redis.FlaskRedis object at 0x7f0a94ba6850>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f0a96405350>, socketio=<flask_socketio.SocketIO object at 0x7f0a964056d0>
[2016-10-27 17:48:08,239 DEBUG app.py:190 <module>] API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open
[2016-10-27 17:48:08,318 DEBUG app.py:190 <module>] API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open
[2016-10-27 17:48:08,356 DEBUG app.py:190 <module>] API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open
[2016-10-27 17:48:08,358 DEBUG app.py:190 <module>] API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

gunicorn.errors.HaltServer HaltServer App failed to load 4

gunicorn启动报错gunicorn.errors.HaltServer – Sudawei – 博客园

python – gunicorn.errors.HaltServer: <HaltServer ‘Worker failed to boot.’ 3> – Stack Overflow

python – How to debug gunicorn failure issues? (Worker failed to boot) – Stack Overflow

gunicorn.errors.HaltServer: <HaltServer ‘Worker failed to boot.’ 3> · Issue #1119 · benoitc/gunicorn · GitHub

Worker failed to boot · Issue #338 · benoitc/gunicorn · GitHub

Worker fails to boot · Issue #351 · benoitc/gunicorn · GitHub

Gunicorn worker failed to boot · Issue #12 · brutasse/graphite-api · GitHub

Flask websocket HaltServer App failed to load 4

websocket HaltServer App failed to load 4

最后发现:

原来是写错了:

    socketio.run()

应该写成是:

from runningfast.app import app, socketio
if __name__ == ‘__main__’:
    #app.run(debug=True)
    # app.run()
    socketio.run(app)

然后就可以正常启动了:

<div–<——————————————————————————
[2016-10-27 18:01:10 +0000] [12932] [INFO] Handling signal: term
[2016-10-27 18:01:10 +0000] [12941] [INFO] Worker exiting (pid: 12941)
[2016-10-27 18:01:11 +0000] [12956] [INFO] Starting gunicorn 19.6.0
[2016-10-27 18:01:11 +0000] [12956] [ERROR] Connection in use: (‘0.0.0.0’, 21085)
[2016-10-27 18:01:11 +0000] [12956] [ERROR] Retrying in 1 second.
[2016-10-27 18:01:12 +0000] [12956] [INFO] Listening at: http://0.0.0.0:21085 (12956)
[2016-10-27 18:01:12 +0000] [12956] [INFO] Using worker: sync
[2016-10-27 18:01:12 +0000] [12965] [INFO] Booting worker with pid: 12965
[2016-10-27 18:01:12 +0000] [12968] [INFO] Booting worker with pid: 12968
[2016-10-27 18:01:12 +0000] [12969] [INFO] Booting worker with pid: 12969
[2016-10-27 18:01:12 +0000] [12970] [INFO] Booting worker with pid: 12970

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:79]:
app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7fd95bab6d90>, redis_store=<flask_redis.FlaskRedis object at 0x7fd95a26f710>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fd95bad1210>, socketio=<flask_socketio.SocketIO object at 0x7fd95bad1590>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:79]:
app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7fd95bab5e10>, redis_store=<flask_redis.FlaskRedis object at 0x7fd95a26f790>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fd95bacd290>, socketio=<flask_socketio.SocketIO object at 0x7fd95bacd610>
DEBUG in app [/root/RunningFast/staging/runningfast/app.py:79]:
app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7fd95bab5e90>, redis_store=<flask_redis.FlaskRedis object at 0x7fd95a26f810>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fd95bacc310>, socketio=<flask_socketio.SocketIO object at 0x7fd95bacc690>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:79]:
app=<Flask ‘runningfast.app’>, api=<flask_restful.Api object at 0x7fd95bab3f10>, redis_store=<flask_redis.FlaskRedis object at 0x7fd95a26d890>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fd95bacc390>, socketio=<flask_socketio.SocketIO object at 0x7fd95bacc710>

【总结】

此处是:

新增了Websocket后,代码笔误为:

from runningfast.app import socketio
if __name__ == ‘__main__’:
    socketio.run()

改为:

from runningfast.app import app, socketio
if __name__ == ‘__main__’:
    socketio.run(app)

即可正常运行了。



发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量