Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing behavior of --reload-dir #2566

Closed
wants to merge 2 commits into from
Closed

Conversation

galvana
Copy link

@galvana galvana commented Jan 16, 2025

Summary

Changing the behavior of the --reload-dir flag in WatchFilesReload. Continuing off the discussion in #2107.

Current Behavior

Currently, when using the --reload flag with Uvicorn, the WatchFilesReload supervisor always watches the current working directory (cwd) in addition to any directories specified via --reload-dir. This means even when users explicitly specify which directories to watch, the supervisor still monitors the entire cwd.

New Behavior

This PR modifies the WatchFilesReload supervisor to:

  • Only watch the directories explicitly specified via --reload-dir when provided
  • Only watch the cwd when no directories are specified via --reload-dir
  • Continue watching directories within cwd when they are explicitly specified

Motivation

This change makes the --reload-dir flag behavior more intuitive and efficient by:

  • Preventing unnecessary file watching when specific directories are provided
  • Reducing system resources used by the file watcher
  • Giving users more precise control over which directories trigger reloads

Example

# Before: Watches both ./api and the entire cwd
uvicorn app:app --reload --reload-dir ./api

# After: Only watches ./api directory
uvicorn app:app --reload --reload-dir ./api

# After: Watches cwd since no directory specified
uvicorn app:app --reload

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@galvana galvana closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant