Implementation for using hmr
with uvicorn
by uvicorn-hmr
#2560
Unanswered
CNSeniorious000
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently
uvicorn --reload
restart the python process every reload, which makes heavy 3rd-party modules being imported everytime.I implemented a
uvicorn-hmr
package to solve this problem. The differences betweenuvicorn main:app --reload
anduvicorn-hmr main:app
can be concluded as:uvicorn-hmr
stop and restart uvicorn servers in the same process, so 3rd-party librarys are cached by default.uvicorn-hmr
depends onhmr
, which performs fine-grained on-demand dependency tracking on every imported name, it yourmain
module depends ona
andb
and onlya.py
is changed,b
will not be invalidate at all.Everybody can have a try by simply replacing
uvicorn --reload main:app
withuvicorn-hmr main:app
.I've tested this on several of middle-sized ASGI Python servers. Looking forward to any responses!
Caution
hmr
are sometimes refer to a feature that updates the page in the browser on the client side when the server code changes. This is not that. This package is a server-side HMR, that reloads the server code when it changes.Beta Was this translation helpful? Give feedback.
All reactions