Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reload flag with uvicorn: can we exclude certain code?

Is it somehow possible to exclude certain part of the code when reloading the scrip with --reload flag?

uvicorn main:app --reload

Use case: I have a model which takes a lot of time loading so I was wondering if there is a way to ignore that line of code when reloading. Or is it just impossible?

like image 446
utengr Avatar asked Sep 29 '20 11:09

utengr


1 Answers

Update

Uvicorn now supports including/excluding certain directories/files to/from watchlist.

  --reload-include TEXT           Set glob patterns to include while watching
                                  for files. Includes '*.py' by default, which
                                  can be overridden in reload-excludes.
  --reload-exclude TEXT           Set glob patterns to exclude while watching
                                  for files. Includes '.*, .py[cod], .sw.*,
                                  ~*' by default, which can be overridden in
                                  reload-excludes.

No there is no way to exclude something, however you can be explicit in what you want to be looked at with the --reload-dir flag:

  --reload-dir TEXT               Set reload directories explicitly, instead
                                  of using the current working directory.

in https://www.uvicorn.org/#command-line-options

like image 153
euri10 Avatar answered Oct 12 '22 21:10

euri10