Skip to content

Commit

Permalink
split serve to reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfischer2781 committed Jan 18, 2023
1 parent 58dfcbc commit dd3c6a1
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions uvicorn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def run(self, sockets: Optional[List[socket.socket]] = None) -> None:
pass

async def serve(self, sockets: Optional[List[socket.socket]] = None) -> None:
with self._capture_exit_signals():
await self._serve(sockets)

async def _serve(self, sockets: Optional[List[socket.socket]] = None) -> None:
process_id = os.getpid()

config = self.config
Expand All @@ -74,24 +78,23 @@ async def serve(self, sockets: Optional[List[socket.socket]] = None) -> None:

self.lifespan = config.lifespan_class(config)

with self._capture_exit_signals():
message = "Started server process [%d]"
color_message = (
"Started server process [" + click.style("%d", fg="cyan") + "]"
)
logger.info(message, process_id, extra={"color_message": color_message})
message = "Started server process [%d]"
color_message = (
"Started server process [" + click.style("%d", fg="cyan") + "]"
)
logger.info(message, process_id, extra={"color_message": color_message})

await self.startup(sockets=sockets)
if self.should_exit:
return
await self.main_loop()
await self.shutdown(sockets=sockets)
await self.startup(sockets=sockets)
if self.should_exit:
return
await self.main_loop()
await self.shutdown(sockets=sockets)

message = "Finished server process [%d]"
color_message = (
"Finished server process [" + click.style("%d", fg="cyan") + "]"
)
logger.info(message, process_id, extra={"color_message": color_message})
message = "Finished server process [%d]"
color_message = (
"Finished server process [" + click.style("%d", fg="cyan") + "]"
)
logger.info(message, process_id, extra={"color_message": color_message})

async def startup(self, sockets: list = None) -> None:
await self.lifespan.startup()
Expand Down

0 comments on commit dd3c6a1

Please sign in to comment.