Flask-SocketIO: SocketIO emit not working from celery task
Hi, I have the following function in my main flask app:
def update_clients(self, *args, **kwargs):
print(args)
socketio.emit('statusmsg', 'message')
And I can see in the celery debug log that the task is getting called and run successfully, but no emission happens. When I emit with the following function:
@app.route('/listener', methods=['POST'])
def listen():
print(request.data)
socketio.emit('statusmsg',request.data.decode())
return redirect(url_for('hello_world'))
The emission works fine.
I am starting the flask server with $ FLASK_APP=hello.py flask run and the celery worker with celery worker -A hello.celery --loglevel=DEBUG
I just need to receive amqp messages from rabbit and emit via socketIO and it is proving really difficult.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (8 by maintainers)
@bigal337 no, that is how you start the Flask server. I’m asking specifically about the Celery worker. See the documentation on how to create the
SocketIOclass on the external process, the arguments are different.