Calling built-in open() or pandas.read_csv() seems to block all other requests to my flask + gevent wsgi webserver despite monkey.patch_all(). Do I need to call special gevent io functions to make them non blocking?
from gevent import monkey, pywsgi, sleep
monkey.patch_all()
import pandas as pd
from flask import Flask
app = Flask(__name__)
FILENAME = 'c:/temp/testcsv.csv'
@app.route('/')
def fastresult():
return 'this should return immediately'
@app.route('/non_blocking_sleep')
def non_blocking_sleep():
sleep(10)
return 'using gevent.sleep does NOT block other reqeusts as expected'
@app.route('/readcsv')
def readcsv():
"""
this blocks any other request before the read completes
"""
df = pd.read_csv(FILENAME)
return df.info()
@app.route('/openfile')
def openfile():
"""
this blocks any other request before the read completes
"""
with open(FILENAME, 'r') as file:
res = file.readlines()
return res[:1000]
http_server = pywsgi.WSGIServer(('', 5000), app)
http_server.serve_forever()
Tested on Anaconda 5.3 (python 3.7) 64 bit on both Windows and Linux.