Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming with gunicorn

I'm trying to stream data from a flask/gunicorn server:

while (True):
    result = json.dumps(tweetQueue.get())
    yield result

However, 30 seconds into the stream, gunicorn times out my connection and stops the stream. How can I make the timeout such that publishing new data to the stream from the server will restart the timeout so the stream will not be terminated?

Thanks!

like image 898
akn320 Avatar asked Feb 13 '23 08:02

akn320


1 Answers

I am answering my own question after doing some more research.

gunicorn server:app -k gevent

This uses asynchronous workers, which have the benefit of using Connection: keep-alive when serving requests. This allows the request to be served indefinitely.

like image 198
akn320 Avatar answered Feb 27 '23 06:02

akn320