support uvicorn reload functionality (#1841)
* support uvicorn reload functionality see: https://github.com/encode/uvicorn/blob/8239373ec649b1a41179070b6ba2c8dc549df63e/uvicorn/main.py#L580-L582 * add docs for --reload --------- Co-authored-by: dni ⚡ <office@dnilabs.com>
This commit is contained in:
+9
-1
@@ -1,4 +1,5 @@
|
||||
import uvloop
|
||||
from uvicorn.supervisors import ChangeReload
|
||||
|
||||
uvloop.install()
|
||||
|
||||
@@ -73,7 +74,14 @@ def main(
|
||||
)
|
||||
|
||||
server = uvicorn.Server(config=config)
|
||||
process = mp.Process(target=server.run)
|
||||
|
||||
if config.should_reload:
|
||||
sock = config.bind_socket()
|
||||
run = ChangeReload(config, target=server.run, sockets=[sock]).run
|
||||
else:
|
||||
run = server.run
|
||||
|
||||
process = mp.Process(target=run)
|
||||
process.start()
|
||||
server_restart.wait()
|
||||
server_restart.clear()
|
||||
|
||||
Reference in New Issue
Block a user