我正在尝试在外部值更改时发送广播。当值发生变化时,Camonitor会调用回调函数,我希望通知所有连接的客户端该值已更改,并且他们需要刷新。
from flask import Flask
from epics import caget, caput, camonitor
from flask_socketio import SocketIO, emit
app = Flask(__name__)
socketio = SocketIO(app)
@socketio.on('connect')
def local_client_connect():
print "Client connected"
def update_image_data(pvname, value, **kw):
# broadcast event
print "Sending broadcast"
socketio.emit('newimage')
if __name__ == "__main__":
# start listening for record changes
camonitor("13SIM1:cam1:NumImagesCounter_RBV", writer=None, callback=update_image_data)
socketio.run(app, debug=True)
当值发生变化时,我的回调函数成功被调用,但广播不起作用。如果我将socketio.emit移动到local_client_connect中,它就会起作用。
编辑:这似乎是一个已知的问题 https://github.com/miguelgrinberg/Flask-SocketIO/pull/213