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

example client: cancel command loop on close of connection #52

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ async def main(args):
ssl_context = None
try:
logging.debug('Connecting to WebSocket…')
async with open_websocket_url(args.url, ssl_context) as conn:
logging.debug('Connected!')
await handle_connection(conn)
logging.debug('Connection closed')
async with trio.open_nursery() as nursery:
async with open_websocket_url(args.url, ssl_context) as conn:
logging.debug('Connected!')
nursery.start_soon(handle_connection, conn)
logging.debug('Connection closed')
nursery.cancel_scope.cancel()
except OSError as ose:
logging.error('Connection attempt failed: %s', ose)
return False
Expand Down