Skip to content

Commit

Permalink
Report the list of binds on trio worker startup
Browse files Browse the repository at this point in the history
This allows the following usage,

    from hypercorn.trio import serve

    ...
    binds: List[str] = await nusery.start(serve, ...)

thereby allowing the caller to know which binds have been made.
  • Loading branch information
pgjones committed Jul 8, 2019
1 parent ccc233c commit aae3c31
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion hypercorn/trio/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def worker_serve(

ssl_context = config.create_ssl_context()
listeners = []
binds = []
for sock in sockets.secure_sockets:
listeners.append(
trio.SSLListener(
Expand All @@ -63,14 +64,16 @@ async def worker_serve(
)
)
bind = repr_socket_addr(sock.family, sock.getsockname())
binds.append(f"https://{bind}")
await config.log.info(f"Running on {bind} over https (CTRL + C to quit)")

for sock in sockets.insecure_sockets:
listeners.append(trio.SocketListener(trio.socket.from_stdlib_socket(sock)))
bind = repr_socket_addr(sock.family, sock.getsockname())
binds.append(f"http://{bind}")
await config.log.info(f"Running on {bind} over http (CTRL + C to quit)")

task_status.started()
task_status.started(binds)
await trio.serve_listeners(partial(Server, app, config), listeners)

except MustReloadException:
Expand Down

0 comments on commit aae3c31

Please sign in to comment.