-
-
Notifications
You must be signed in to change notification settings - Fork 754
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The examples on the description shows uvicorn.serve
, but that is not available yet. We need to add from uvicorn.main import serve
on the __init__.py
.
@euri10 Do you have something against this or can we we merge it? |
nothing against, that may be a breaking change though for some people, @florimondmanca will know for sure, so maybe hold it onto a minor bump if patches need to be released in between |
Well I think the general idea is quite nice. Tho as @HansBrende pointed out, seems there’s a distinction and decision to take about whether the k don’t have much more background to tell which would best address the issues this aims at, though. Just thought I’d raise that distinction as something that should be discussed before merging. In a all cases, one of this or #1012 should end up merged and the other one closed, right? |
I also agree with @HansBrende that the |
@@ -444,6 +444,13 @@ def load(self) -> None: | |||
|
|||
self.lifespan_class = import_from_string(LIFESPAN[self.lifespan]) | |||
|
|||
if (self.reload or self.workers > 1) and not isinstance(self.app, str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this check go in the constructor? By the time we get here, we are already in the subprocess I believe...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check should be combined with import_from_string(self.app)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? Isn't it preferable to "fail fast" in the main process rather than failing later in possibly N subprocesses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user provides a string, checks the type in one place, but tries to import it in another far away, don't you think this is unreasonable?
If it is for this purpose, then import_from_string(self.app)
should also "fail fast".
Let's continue on #1012. It's easier, yep. |
Related links:
To solve #742 , a short and simple code:
To solve #1151
To solve #451 and #1091