python - How to run flask socket.io on localhost (xampp) -
the tutorials have seen use following code run server:
if __name__ == '__main__': socketio.run(app)
my __init__.py
file is:
from flask import flask flask.ext.sqlalchemy import sqlalchemy sqlalchemy.orm import sessionmaker sqlalchemy import * flask.ext.socketio import socketio, emit app = flask(__name__) socketio = socketio(app) app.debug = true engine = create_engine('mysql://root:my_pw@localhost/db_name') dbsession = sessionmaker(bind=engine) import couponmonk.views
my views.py
file contains @app.route
, @socketio
decorators.
my question is, should placing code:
socketio.run(app)
when put in __init__.py_
file, receive errors:
file "/opt/lampp/htdocs/flaskapp/flask.wsgi", line 7, in <module> couponmonk import app application file "/home/giri/desktop/couponmonk/venv/couponmonk/__init__.py", line 14, in <module> socketio.run(app) file "/home/giri/desktop/couponmonk/venv/lib/python2.7/site-packages/flask_socketio/__init__.py", line 411, in run run_with_reloader(run_server) file "/home/giri/desktop/couponmonk/venv/lib/python2.7/site-packages/werkzeug/serving.py", line 632, in run_with_reloader return run_with_reloader(*args, **kwargs) file "/home/giri/desktop/couponmonk/venv/lib/python2.7/site-packages/werkzeug/_reloader.py", line 231, in run_with_reloader sys.exit(reloader.restart_with_reloader()) systemexit: 2
author of flask-socketio here.
unfortunately extension cannot work standard web server, not able host app uses on apache/mod_wsgi. need use gevent server, , not generic one, 1 customized socket.io.
that means apache out (it not support websocket traffic). uwsgi out (supports gevent, not possible use custom gevent server). side note, python 3 out, gevent runs on python 2 (though think there's going news soon, i'm working on ideas socketio running on python 3 right now).
the choices have given in documentation. summary:
socketio.run(app)
, runs custom socketio gevent server directly.- gunicorn custom socketio worker (command line shown in docs)
you can put nginx reverse proxy in front of server if like. configuration shown in docs.
good luck!
Comments
Post a Comment