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
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions uvicorn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from uvicorn.config import Config
from uvicorn.main import Server, main, run
from uvicorn.main import Server, main, run, serve

__version__ = "0.15.0"
__all__ = ["main", "run", "Config", "Server"]
__all__ = ["main", "run", "serve", "Config", "Server"]
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