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

Allow dependency injection Config and Server #1248

Closed
wants to merge 10 commits into from
6 changes: 5 additions & 1 deletion uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ def main(

def run(app: typing.Union[ASGIApplication, str], **kwargs: typing.Any) -> None:
config = Config(app, **kwargs)
server = Server(config=config)

if (config.reload or config.workers > 1) and not isinstance(app, str):
logger = logging.getLogger("uvicorn.error")
Expand All @@ -438,6 +437,11 @@ def run(app: typing.Union[ASGIApplication, str], **kwargs: typing.Any) -> None:
)
sys.exit(1)

server = Server(config=config)
serve(config, server)


def serve(config: Config, server: Server) -> None:
abersheeran marked this conversation as resolved.
Show resolved Hide resolved
if config.should_reload:
sock = config.bind_socket()
ChangeReload(config, target=server.run, sockets=[sock]).run()
Expand Down