When running a Flask application in combination with an async firestore client, a runtime error 'Event loop is closed' appears the second time loading the page.
Example app:
import firebase_admin
from firebase_admin import credentials, firestore_async
from flask import Flask
cred = credentials.Certificate('credentials.json')
firebase_admin.initialize_app(cred)
db = firestore_async.client()
app = Flask(__name__)
@app.route('/')
async def hello_world():
await db.collection("product").get()
return 'Hello, World!'
if __name__ == "__main__":
app.run(debug=True)
I tried to run this application, which works correctly until the second load of the page. When running the app with a wsgi worker, the error sometimes appears and sometimes does not. I also tried creating a new client for every request, but the issue remains.
pip install flask[async]
(flask.palletsprojects.com/en/3.0.x/async-await)