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

Documentation improvement #558

Closed
warvariuc opened this issue Oct 8, 2015 · 2 comments
Closed

Documentation improvement #558

warvariuc opened this issue Oct 8, 2015 · 2 comments
Labels

Comments

@warvariuc
Copy link

http://aiohttp.readthedocs.org/en/stable/web.html#websockets

@asyncio.coroutine
def websocket_handler(request):

    ws = web.WebSocketResponse()
    ws.start(request)

    while True:
        msg = yield from ws.receive()

        if msg.tp == aiohttp.MsgType.text:
            if msg.data == 'close':
                yield from ws.close()
            else:
                ws.send_str(msg.data + '/answer')
        elif msg.tp == aiohttp.MsgType.close:
            print('websocket connection closed')
        elif msg.tp == aiohttp.MsgType.error:
            print('ws connection closed with exception %s',
                  ws.exception())

    return ws

print('ws connection closed with exception %s', ws.exception()) -> print('ws connection closed with exception %s' % ws.exception())

Also when print('websocket connection closed') happens after that there is no break -- the loop will still run forever. I am suggesting to replace while True: -> while not ws.closed:

@asvetlov
Copy link
Member

asvetlov commented Oct 8, 2015

Fixed by 50fa781
Thanks

@lock
Copy link

lock bot commented Oct 29, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants