I created a simple FastAPI app. Sometimes the API call works, but other times it gives a random error message.
Here is a minimum reproducible code:
from fastapi import FastAPI
import uvicorn
import time
from loguru import logger
import sys
logger.add("file_{time}.log")
logger.add(sys.stdout, colorize=True, format="<green>{time}</green> <level>{message}</level>")
app = FastAPI()
@app.get("/")
async def root():
logger.info("starting SLEEP loop")
for i in range(0, 63):
time.sleep(10)
logger.info(f"slept for {(i+1)*10} seconds or {float((i+1)*10/60)} minutes")
return {"message": "Hello World"}
uvicorn.run(app)
Here is the error it gives randomly:
How to solve this? I suspect this has got something to do with the 10+ minutes I am running this for.