Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FastAPI with uvicorn doesn't update

Tags:

python

fastapi

I am using FastAPI with Uvicorn. Everything was working perfectly, but now it seems that nothing is updating. I have changed a method and it does not recognize the change, I have created a new method and it does not recognize it either. Execution: uvicorn API:app --reload.

For example, this is a simple code that does not recognize:

@app.get("/clientes/cumple", response_model=List[Cliente])
async def get_cliente_cumple(dia: int, mes: int):
    clientes = db.obtener_clientes_por_fecha_nacimiento(dia, mes)
    if not clientes:
        raise HTTPException(status_code=404, detail="Cliente no encontrado")
    return [Cliente(codigoclientes=c["codigoclientes"],titular=c["titular"],fnacim=c["fnacim"],dni_cif=c["dni_cif"], telf=c["telf"]) for c in clientes]

I finish it and restart, but nothing changes.

In the terminal where I execute the API, it looks like it recognize the changes, but usually when I do a request, the terminal also shows the HTTP Code result and right now only shows the alleged changes.

Does anyone know what might be happening?

like image 551
Rodkaiser Avatar asked Jun 08 '26 06:06

Rodkaiser


1 Answers

I will elaborate more on the comment written by Yurii Motov. My solution may not be perfect but it solved my problem and I think it adds some value. I stopped all instances of my app running, then I started again my app it worked out. My solution is based on Windows. First, I checked all uvicorn instances running by the following command

tasklist /FI "IMAGENAME eq python.exe"

In my case, there were two Python instances running.

enter image description here

I terminated them with the following commands. PID can be found from the previous image (red arrow).

taskkill /PID 24508  /F

taskkill /PID 16024  /F

Then I started again my app and all changes could be seen on fastapi swagger.

uvicorn main:app --reload
like image 59
Ilias Machairas Avatar answered Jun 10 '26 18:06

Ilias Machairas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!