[Python] Uvicorn reload_excludes not working for one directory but working for another...

Discussão em 'Python' iniciado por Stack, Maio 24, 2025.

  1. Stack

    Stack Membro Participativo

    I'm running a FastAPI application with uvicorn and using reload_excludes to prevent the server from reloading when files are added to certain directories. The issue is that the exclusion works for one directory (generated_scripts) but completely fails for another directory (generated_tools) that has the exact same structure and configuration.

    Directory Structure


    src/
    └── ai_processing/
    ├── main.py
    ├── generated_scripts/ # Exclusion works - no reload when files added
    └── generated_tools/ # Exclusion fails - server reloads when files added


    Both directories:

    • Exist at the same level
    • Are created with the same permissions
    • Have identical structure
    • Are specified with identical patterns in reload_excludes
    Current Code


    if __name__ == "__main__":
    uvicorn.run(
    "main:app",
    host="127.0.0.1",
    port=8000,
    reload=True,
    reload_excludes=[
    "src/ai_processing/generated_scripts/*",
    "src/ai_processing/generated_tools/*"
    ]
    )

    1. Tried all of these patterns:

    reload_excludes=[
    "src/ai_processing/generated_scripts/*",
    "src/ai_processing/generated_tools/*",
    "src/ai_processing/generated_scripts/**",
    "src/ai_processing/generated_tools/**",
    "**/generated_scripts/**",
    "**/generated_tools/**",
    "src\\ai_processing\\generated_tools\\*", # Windows path separator
    ]


    1. Verified directory existence and structure


    2. Tried creating directories if they don't exist

    pythonPath("src/ai_processing/generated_scripts").mkdir(parents=True, exist_ok=True)
    Path("src/ai_processing/generated_tools").mkdir(parents=True, exist_ok=True)

    1. Tried using reload_dirs in combination

    uvicorn.run(
    "main:app",
    reload=True,
    reload_dirs=["src"],
    reload_excludes=[
    "src/ai_processing/generated_scripts/*",
    "src/ai_processing/generated_tools/*"
    ]
    )

    Continue reading...

Compartilhe esta Página