I want to start another python process from within my flask application. This process prints some feedback once and then. I then try to send this feedback to the frontend of my application using socketio. However, the messages sent from this subprocess never arrive.
The function that executes my program:
def executePY(cmd):
popen = Popen(cmd, stdout=PIPE, universal_newlines=True)
for stdout_line in iter(popen.stdout.readline, ""):
yield stdout_line
popen.stdout.close()
The function that calls the Execution and then waits for responses:
def test():
for statement in executePY(['python3', '-u', 'bla.py']):
send_to_frontend(statement)
The function sending the messages to the frontend:
def send_to_frontend(msg):
print(msg) # The Message arrives here!
socketio.emit('message', msg, namespace='/bla')
Receiving the messages in the frontend:
var namespace = '/editor';
var socket = io.connect('http://127.0.0.1:5000' + namespace);
// Python Output
socket.on('message', function(msg) {
console.log(msg); // No Message here!
});