Python Forum

Full Version: Problem With Database Calls and Load
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have created an API service using FastAPI, Python and MySQL. The API allows acces to some data in a database. An api request from fastapi triggers a function call which runs two database read queries that then return a result. The database is accessed using mysql.connector and a cursor. If just one api request is made every few seconds, everything seems to work. However, any faster than that (if i hit the refresh button in browser quickly) the program seems to crash at the point the second db query is made. The database contains quite a few records, so with just 1 request being made that can take 1-5 seconds on average for the second db call. Does anyone know what might be going wrong and a solution? I am a newbie so quite likely I have done something a bit silly.
I think I fixed it, I wasn't opening/closing the database connection properly Smile