I have the following thread that emits to the websocket that is working, but if I have two browser windows ( or multiple clients connect) they all see the same data being pushed. In the example code from https://github.com/miguelgrinberg/Flask-SocketIO appears that I shouldn't even need to specify broadcast=False, but I tried it and it still shows up in all connected websocket windows.
@socketio.on('job_submit', namespace='/socket')
def job_submit(message):
emitter('received job')
# start job and kick off thread to read and emit output of job (setup in redis list)
job = background_task.delay()
runme = test_duplicates(message)
if runme:
threads[len(threads) + 1] = {'thread': None, 'thread_lock': Lock()}
global thread
thread = threads[len(threads)]['thread']
with threads[len(threads)]['thread_lock']:
if thread is None:
thread = socketio.start_background_task(output_puller, job)
threads[len(threads)]['thread'] = thread
threads[len(threads)]['thread'].setName(message['data'])
def output_puller(job):
while job.state != 'SUCCESS' and job.state != 'FAILURE':
result = r_server.lpop(job.id)
if result:
socketio.emit('my_response', {'data': result.decode()}, namespace='/socket', broadcast=False)
print(result)