0

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.

2
  • Flask is a synchronous web framework. You should not be using async routes with it.
    – shiv
    Commented Jan 23, 2024 at 18:02
  • They do have support for async when installing with pip install flask[async] (flask.palletsprojects.com/en/3.0.x/async-await)
    – lennertcl
    Commented Jan 24, 2024 at 9:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.