![]() |
Problem With Database Calls and Load - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Problem With Database Calls and Load (/thread-35595.html) |
Problem With Database Calls and Load - Timbo03 - Nov-20-2021 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. RE: Problem With Database Calls and Load - Timbo03 - Nov-21-2021 I think I fixed it, I wasn't opening/closing the database connection properly ![]() |