question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support --ignore or --reload-file option

See original GitHub issue

Is your feature related to a problem? Please describe.

My application’s file structure is as follows:

cloud-app git:(dev) ✗ tree -L 1
.
├── Dockerfile
├── README.md
├── frontend
├── gatekeeper
├── iam
├── main.py
├── manage.py
├── requirements.txt
├── templates
└── util.py

frontend is a React SPA, gatekeeper and iam belong to a Django application that we mount as an ASGI sub-application alongside our fastapi ASGI app which is defined in main.py.

Currently I run uvicorn as follow:

uvicorn main:app --reload --host 0.0.0.0 --port 8000 --reload-dir iam --reload-dir gatekeeper

I would like to see one of the following (or both!) flags supported:

  • --ignore-dir frontend: would enable me to ignore changes to frontend source code that are triggering a large number of reloads of my uvicorn app, despite those changes being irrelevant;
  • --reload-file main.py: would enable me to whitelist specific files to watch.

I believe WatchDog can be configured to ignore/exclude files and dirs based on pattern matching.

Refs

https://pythonhosted.org/watchdog/api.html#watchdog.events.RegexMatchingEventHandler.ignore_regexes https://pythonhosted.org/watchdog/api.html#watchdog.events.PatternMatchingEventHandler.ignore_patterns

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
Andrew-Chen-Wangcommented, May 28, 2021

For anyone looking to monkey patch uvicorn with watchgod for the moment, you can do something like this: https://github.com/pydanny/cookiecutter-django/pull/3168

import os
import sys

import uvicorn
from uvicorn.supervisors.watchgodreload import CustomWatcher


ignored = {
    "templates",
    "static",
    "staticfiles",
    "compose",
    ".ipython",
    "bin",
    ".pytest_cache",
    ".idea",
    "media",
    "htmlcov",
    "docs",
    "locale",
    "requirements",
}


class WatchgodWatcher(CustomWatcher):
    def __init__(self, *args, **kwargs):
        self.ignored_dirs.update(ignored)
        super(WatchgodWatcher, self).__init__(*args, **kwargs)


uvicorn.supervisors.watchgodreload.CustomWatcher = WatchgodWatcher
if __name__ == "__main__":
    sys.path.insert(0, os.path.abspath("/app"))
    uvicorn.run("config.asgi:application", host="0.0.0.0", reload=True)

Although that’s only dirs only, there’s also a ignored_file_regexes tuple-typed attribute that you can use as well since uvicorn uses DefaultWatcher.

2reactions
slavaGanzincommented, Jul 10, 2021

Vote for #820

And it would be great if uvicorn.supervisors.watchgodreload.DefaultWatcher.ignored_file_regexes had image, video and log files in it. Cause it’s expected behavior for servers to save uploaded files in app folder

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore All when unsaved changes and file changed on disk is ...
In a previous version, I'm pretty sure it just gave me the option to Reload or Ignore for each individual file. This was...
Read more >
Developers - Support --ignore or --reload-file option -
Support --ignore or --reload-file option.
Read more >
VS2008: Disable asking whether to reload files changed ...
For VS2008: Tools > Options > Documents > Detect when a file is changed outside the environment. For VS2010/2012/2013/2015: Tools > Options >...
Read more >
How to Enable Silent Reloading in TexStudio? - TeX
Reloading overwrites the editor content with the file from disk. This cannot be undone. You can permanently enable silent reloading in the ...
Read more >
Reopen documents on Reload after file modification detected
Tools > Options > Environment > Documents > Detect when file is changed outside the environment > Reload modified files unless there are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found