Skip to content

Trouble getting real time messages with gevent & gunicorn #2000

Closed Answered by N-Jay-Dee
N-Jay-Dee asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for the swift reply, you were absolutely correct. I was attempting to use a method for real time reading of the standard subprocess module that doesn't work with the monkeypatched gevent version.

For anyone with a similar issue I was able to get it to work with the following:

def emit_stream(stream, event):

    while not stream.closed:
        message = stream.readline()

        if not message: 
            break
        
        socketio.emit(event, { 'data': message.strip() })

process = Popen(file_path, stdout=PIPE, stderr=PIPE, shell = True, universal_newlines=True)

gevent.spawn(emit_stream, process.stdout, 'stdout_chunk')
gevent.spawn(emit_stream, process.stderr, 'stderr…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by N-Jay-Dee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants