Skip to content

Commit

Permalink
Updated an example to refer to BaseExceptionGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Jan 30, 2022
1 parent 370e40f commit e2fbec0
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/source/tutorial/echo-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

CONNECTION_COUNTER = count()


async def echo_server(server_stream):
# Assign each connection a unique number to make our debug prints easier
# to understand when there are multiple simultaneous connections.
Expand All @@ -21,18 +22,20 @@ async def echo_server(server_stream):
print(f"echo_server {ident}: received data {data!r}")
await server_stream.send_all(data)
print(f"echo_server {ident}: connection closed")
# FIXME: add discussion of MultiErrors to the tutorial, and use
# MultiError.catch here. (Not important in this case, but important if the
# server code uses nurseries internally.)
# FIXME: add discussion of (Base)ExceptionGroup to the tutorial, and use
# exceptiongroup.catch() here. (Not important in this case, but important
# if the server code uses nurseries internally.)
except Exception as exc:
# Unhandled exceptions will propagate into our parent and take
# down the whole program. If the exception is KeyboardInterrupt,
# that's what we want, but otherwise maybe not...
print(f"echo_server {ident}: crashed: {exc!r}")


async def main():
await trio.serve_tcp(echo_server, PORT)


# We could also just write 'trio.run(trio.serve_tcp, echo_server, PORT)', but real
# programs almost always end up doing other stuff too and then we'd have to go
# back and factor it out into a separate function anyway. So it's simplest to
Expand Down

0 comments on commit e2fbec0

Please sign in to comment.