flask-socketio

Sending events outside from Flask SocketIO event context

老子叫甜甜 提交于 2019-12-11 07:59:03
问题 When I try to send a socket message outside from the SocketIO event context, the message does not arrive at the client. Method outside of the context: @main.route('/import/event', methods=['POST']) def update_client(): from .. import socketio userid = request.json['userid'] data = request.json current_app.logger.info("New data: {}".format(data)) current_app.logger.info("Userid: {}".format(userid)) socketio.emit('import', data, namespace='/events', room=userid) return 'ok' I also tried: with

Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)

删除回忆录丶 提交于 2019-12-10 09:36:02
问题 I am always getting this error when running my Flask App with Websockets. I have tried to follow this guide - http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent I have a flask app that provides the GUI interface for my network sniffer. The sniffer is inside a thread as shown below : ( l is the thread for my sniffer; isRunning is a boolean to check if the thread is already running) try: if l.isRunning == False: # if the thread has been shut down l.isRunning = True #

flask socketio emit to specific user

那年仲夏 提交于 2019-12-09 12:33:49
问题 I see there is a question about this topic, but the specific code is not outlined. Say I want to emit only to the first client. For example (in events.py): clients = [] @socketio.on('joined', namespace='/chat') def joined(message): """Sent by clients when they enter a room. A status message is broadcast to all people in the room.""" #Add client to client list clients.append([session.get('name'), request.namespace]) room = session.get('room') join_room(room) emit('status', {'msg': session.get(

Flask-Socketio takes extremely long to connect on Heroku

巧了我就是萌 提交于 2019-12-08 09:12:51
问题 All code works perfectly fine on my local machine, just not on Heroku. Have read through many issues on github / other errors on Flask-socketio and nothing seems to work. I left my browser running for about 20mins when using the eventlet setup and I saw the .on('connect') run correctly but none of the other parts of the code. Here's my current procfile: web: gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --chdir nickdima wsgi:app heroku features:enable http-session

How to send message from server to client using Flask-Socket IO

五迷三道 提交于 2019-12-08 01:10:24
问题 I'm trying to create a python app that can send message from server to client. Currently I'm using this sample code from here. It's a chat app and it's working fine. I tried to modified the app and add a new function in the server side python code that will print a message "Dummy" into the client but seems like it didn't work. Here's my html code: index.html <body> <ul id="messages"></ul> <ul id="output"></ul> <form action=""> <input id="m" autocomplete="off" /><button>Send</button> </form>

using flask-migrate with flask-script, flask-socketio and application factory

时光怂恿深爱的人放手 提交于 2019-12-07 08:20:49
问题 I'm creating an flask application with the application factory approach, but have an issue when using Flask-Migrate with socketio and flask-script. The problem is that I'm passing my create_app function to the Manager but I need to pass the app to my socketio.run() as well. And right now I can't seem to see a solution. Is there any way I can combine these two solutions? manage.py: #app = create_app(False) <--- Old approach #manager = flask_script.Manager(app) manager = flask_script.Manager

How to send message from server to client using Flask-Socket IO

不羁的心 提交于 2019-12-06 08:09:08
I'm trying to create a python app that can send message from server to client. Currently I'm using this sample code from here . It's a chat app and it's working fine. I tried to modified the app and add a new function in the server side python code that will print a message "Dummy" into the client but seems like it didn't work. Here's my html code: index.html <body> <ul id="messages"></ul> <ul id="output"></ul> <form action=""> <input id="m" autocomplete="off" /><button>Send</button> </form> <script src="{{url_for('static', filename='assets/vendor/socket.io.min.js')}}"></script> <script src="{

using flask-migrate with flask-script, flask-socketio and application factory

六月ゝ 毕业季﹏ 提交于 2019-12-05 12:48:05
I'm creating an flask application with the application factory approach, but have an issue when using Flask-Migrate with socketio and flask-script. The problem is that I'm passing my create_app function to the Manager but I need to pass the app to my socketio.run() as well. And right now I can't seem to see a solution. Is there any way I can combine these two solutions? manage.py: #app = create_app(False) <--- Old approach #manager = flask_script.Manager(app) manager = flask_script.Manager(create_app) manager.add_option("-t", "--testing", dest="testing", required=False) manager.add_command(

Python - Flask-SocketIO send message from thread: not always working

僤鯓⒐⒋嵵緔 提交于 2019-12-03 09:27:21
问题 I am in the situation where I receive a message from the client. Within the function that handles that request (@socketio.on) I want to call a function where some heavy work is done. This should not result in blocking the main thread and the client is thought to be informed once the work is done. Thus I start a new thread. Now I encounter a really strange behavior: The message never reaches the client. However, the code reaches that particular spot where the message is sent. Even more

Python - Flask-SocketIO send message from thread: not always working

人走茶凉 提交于 2019-12-03 00:01:41
I am in the situation where I receive a message from the client. Within the function that handles that request (@socketio.on) I want to call a function where some heavy work is done. This should not result in blocking the main thread and the client is thought to be informed once the work is done. Thus I start a new thread. Now I encounter a really strange behavior: The message never reaches the client. However, the code reaches that particular spot where the message is sent. Even more surprising is the fact that if there is nothing happening in the thread except for the message being sent to