Вызов встроенного open () или pandas.read_csv () , кажется, блокирует все другие запросы к моему веб-серверу flask + gevent wsgi, несмотря на monkey.patch_all ().Нужно ли вызывать специальные функции gevent io, чтобы они не блокировались?
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()
Протестировано на 64-разрядной версии Anaconda 5.3 (python 3.7) как в Windows, так и в Linux.