Replies: 2 comments 1 reply
-
Hiya @tchaton - thanks for raising this. I'm going to bump this into a discussion first, because I think that'll be a better starting point. (See #1374) Right now I'm generally trying to push for feature pause on uvicorn. I'd rather we don't consider new additions until the existing issue/PR backlog is comprehensively addressed. This'll help make sure we're focusing on stability and bug fixes. Once we're confident that we've got the project management to a really nice sustainable point we're more likely to consider feature development. |
Beta Was this translation helpful? Give feedback.
-
Thanks for answering @tomchristie. I actually found a cleaner solution. I am just afraid the run method changes on your side, but it seems quite stable. class PatchUvicornServer(uvicorn.Server):
has_started_queue = None
def run(self, sockets=None):
self.config.setup_event_loop()
loop = asyncio.get_event_loop()
asyncio.ensure_future(self.serve(sockets=sockets))
if self.has_started_queue:
asyncio.ensure_future(self.check_is_started(self.has_started_queue))
loop.run_forever()
async def check_is_started(self, queue):
while not self.started:
await asyncio.sleep(1)
queue.put("SERVER_HAS_STARTED")
app = ...
def start_server(..., has_started_queue=None)
if has_started_queue:
PatchUvicornServer.has_started_queue = has_started_queue
# uvicorn is doing some uglyness by replacing uvicorn.main by click command.
sys.modules["uvicorn.main"].Server = PatchUvicornServer
uvicorn.run(app=app, host=host, port=port, log_level="error") IMO, I would really like to see the run method take a server-class to enable customization. def run(server_cls):
server_cls = server_cls or Server
server = Server(config) |
Beta Was this translation helpful? Give feedback.
-
Checklist
Is your feature related to a problem? Please describe.
I would like to know if the server is ready without hitting the endpoint. I would like to simply use a queue to know if the server is ready.
Describe the solution you would like.
Here is my current hack to know when the server is ready outside the main thread. The problem is the run method is changing on the uvicorn side and I can't patch it, otherwise I would be missing on latest features.
Describe alternatives you considered
I didn't consider any other.
Additional context
None
Beta Was this translation helpful? Give feedback.
All reactions