1

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!
});
SparkierFlunky
  • 482
  • 4
  • 18
  • Maybe I need to clarify, when I simply call `send_to_frontend('test')` without starting a subprocess, everything works like a charm... – SparkierFlunky Feb 19 '18 at 08:52

1 Answers1

0

When searching for answers to this, i stumbled upon the following question: https://stackoverflow.com/a/34649180/4620643

following the approach of simply replacing

import subprocess

with

from eventlet.green import subprocess

fixed the issue.

SparkierFlunky
  • 482
  • 4
  • 18