Multiple calls to gevent flask api not processed in parallel

692 Views Asked by At

I have a monkey patched flask api with gevent that does not seem to process requests in parallel.

tested with gevent version = 1.4.0; python 2.7 and python 3.7

(I also tried with gevent.sleep, still does not work)

from gevent import monkey
monkey.patch_all()
from flask import Flask
from gevent.pywsgi import WSGIServer
import gevent
import time
app = Flask(__name__)

@app.route('/')
def overview():
    print('1')
    time.sleep(10)
    print('2')
    return "ok"


WSGIServer(('', 3341), app).serve_forever()

Output for two requests sent via different tabs in browser:

1
2
::1 - - [2020-01-09 16:51:42] "GET / HTTP/1.1" 200 117 10.006179
1
2
::1 - - [2020-01-09 16:51:52] "GET / HTTP/1.1" 200 117 10.005313

shows that the server is processing requests sequentially.

Thanks for helping.

1

There are 1 best solutions below

0
On

I found the Chrome browser was the culprit, after learning based on this answer: https://stackoverflow.com/a/62912019/253127

basically Chrome is trying to cache the result of the first request, and then serve that to the additional tabs. Oddly it seemed like only my first incognito window worked, and then subsequent incognito windows also stalled.

So overall, using a window of each:

  • normal Chrome
  • Chrome incognito
  • MS Edge

I finally saw 3 immediate print('1') statements show up on stdout