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

add run_server(server) convenience func #1012

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rmorshea
Copy link

@rmorshea rmorshea commented Mar 19, 2021

the run() function contains valuable logic for kicking off the StatReloader and the Multiprocess workers, however it does not give you access to the server instance before starting and subsequently blocking. thus splitting out the server start logic into a function accepting an already initialized server instance solves this problem.

I'll add tests/docs for this once it's generally accepted as a good idea

the run() function contains valuable logic for kicking of
the StatReloader and the Multiprocess workers, however it
does not give you access to the server instance before
starting and subsequently blocking. thus splitting out the
server start logic into a function accepting an already
intialized server instance solves this problem.
@Kludex
Copy link
Sponsor Member

Kludex commented Jun 10, 2021

@rmorshea Why would you want to have access to the Server object?

@rmorshea
Copy link
Author

rmorshea commented Jun 10, 2021

@Kludex I'm running the server in a thread and want to block the parent thread until Server.started is True - examples from #742 suggest sub-classing Server to accomplish this, but that feels overly complicated for something that ought to be relatively simple.

@rmorshea
Copy link
Author

rmorshea commented Jun 10, 2021

In fact this comment suggests a relatively similar change. In that case the create_runner() function returns a Server instance rather than accepting an already initialized one (as mine proposes) but the principle is the same.

@HansBrende
Copy link
Contributor

HansBrende commented Nov 29, 2021

@Kludex @florimondmanca @euri10 I would personally recommend this PR over #1248... simple & elegant, plus it was written first! Just needs to resolve conflicts from master and add "run_server" to __all__ in uvicorn/__init__.py.

@rmorshea
Copy link
Author

I'd be happy to make the requisite changes once the choice is made to go with this PR over the other.

@Kludex
Copy link
Sponsor Member

Kludex commented Apr 23, 2022

Thanks for the PR @rmorshea . Sorry for taking so long to act here! 😞

I'm going to follow this idea on #1248.

@Kludex Kludex closed this Apr 23, 2022
@HansBrende
Copy link
Contributor

@Kludex IMO this PR is better than the other one which has a bunch of issues (hence the multitude of comments)... why not close that one instead? See, e.g., #1248 (comment)

@Kludex
Copy link
Sponsor Member

Kludex commented Apr 23, 2022

I'm not happy about having multiple ways to run uvicorn in code e.g. run and run_server.

I'm also not that convinced about #1248 either fwiw. 😅

In any case, if you want, feel free to open a discussion, and propose the alternatives. I don't think a discussion presenting the possibilities, and why we should do this was created in a good way to convince others about this (or similar).

@HansBrende
Copy link
Contributor

HansBrende commented Apr 23, 2022

@Kludex both PRs introduce run_server() fyi. The main reason I see being the ability to control the creation of your config/server before running, which Server.run() almossstttt does except it ignores the config's reload options.

(Food for thought/alternative: rather than adding yet another function, could just stuff the reload logic in Server.run() so that we can simply do create_server_however_i_want(create_config_however_i_want()).run()).

@Kludex
Copy link
Sponsor Member

Kludex commented Apr 23, 2022

@Kludex both PRs introduce run_server() fyi.

Oh... True. I didn't see that, sorry.

But after checking it again, the PRs are pretty similar anyway.

@HansBrende
Copy link
Contributor

HansBrende commented Apr 23, 2022

@Kludex yep, quite similar, hence why I'd suggest re-opening this one and closing the other:

  1. in-so-far as they are similar, this one was written first (basic PR etiquette to use the original PR rather than a copycat PR)
  2. in-so-far as they are different, this one is better

@Kludex Kludex reopened this May 10, 2022
@Kludex Kludex added this to the Version 0.21.0 milestone Dec 16, 2022
@Kludex Kludex mentioned this pull request Dec 16, 2022
16 tasks
@Kludex Kludex modified the milestones: Version 0.21.0, Version 0.22.0 Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants