Python 2.7 使用烧瓶、nginx和gunicorn设置gevent插座
下面是我的python代码Python 2.7 使用烧瓶、nginx和gunicorn设置gevent插座,python-2.7,nginx,gunicorn,gevent-socketio,Python 2.7,Nginx,Gunicorn,Gevent Socketio,下面是我的python代码 from gevent import monkey;monkey.patch_all() from flask import Flask,render_template, url_for, request, redirect, flash,jsonify,session,Markup from socketio import socketio_manage from socketio.namespace import BaseNamespace from socket
from gevent import monkey;monkey.patch_all()
from flask import Flask,render_template, url_for, request, redirect, flash,jsonify,session,Markup
from socketio import socketio_manage
from socketio.namespace import BaseNamespace
from socketio.server import SocketIOServer
app=Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
class ChatNamespace(BaseNamespace):
def recv_connect(self):
print "successfully connected"
self.emit('show_result','successfully connect')
def on_receive_message(self,msg):
print "message is "+msg["data"]
self.emit('show_result2',msg["data"])
@app.route('/')
def index():
#print "in the function"
return render_template('index.html')
@app.route("/socket.io/<path:path>")
def run_socketio(path):
socketio_manage(request.environ, {'/test': ChatNamespace})
return 'ok'
if __name__=='__main__':
#app.run(debug=True, port=80, host='0.0.0.0')
app.debug=True
#app.run()
SocketIOServer(('0.0.0.0', 5000), app,resource="socket.io").serve_forever()
print "successfull listen to socket"
每次运行应用程序时,我都使用以下命令gunicorn main2:app-b本地主机:5000 我知道在实时服务器上运行此gevent socketio应用程序时,我丢失了很多信息。 有人能帮我吗,我对这种web套接字技术完全陌生你试过吗 如果您试图在没有扩展的情况下运行,则需要socketio gunicorn worker来运行您的应用程序
gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker module:app
gunicorn --worker-class socketio.sgunicorn.GeventSocketIOWorker module:app