Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using emit in a background task is not working #455

Open
averri opened this issue Dec 29, 2017 · 0 comments
Open

Using emit in a background task is not working #455

averri opened this issue Dec 29, 2017 · 0 comments

Comments

@averri
Copy link

averri commented Dec 29, 2017

Using emit in a background task is not working together with Popen. Please refer to the example below. I've tried to use the Popen from Eventlet too with no luck.

Environment: Windows 10
Python: 3.6.4

from subprocess import PIPE, Popen
from flask import Flask
from flask_socketio import SocketIO, emit

app = Flask(__name__)
io = SocketIO(app, async_mode='eventlet')

def emit_docker_logs():
    while True:
        command = ['docker', 'logs', '-f', 'web-server']
        proc = Popen(command, stdout=PIPE, stderr=PIPE, universal_newlines=True)
       
        while proc.poll() is None:
            line = str(proc.stdout.readline(), 'utf-8')
            if line:
                print(line) # This gets printed.
                io.emit('logdata', line) # The client does not receive this line.
        print(proc.stderr.readline())
        io.sleep(10)


if __name__ == '__main__':
    io.start_background_task(target=emit_docker_logs)
    io.run(app)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant