Example webterm.py fails, send_str never awaited.
ilar opened this issue · comments
If you try to run webterm.py, it will fail, giving the errors:
webterm.py:86: RuntimeWarning: coroutine 'WebSocketResponse.send_str' was never awaited ws.send_str(terminal.dumps())
webterm.py:90: RuntimeWarning: coroutine 'WebSocketResponse.send_str' was never awaited ws.send_str(terminal.dumps())
This is with python3.5 and 3.6, and aiohttp 3.3.2.
This is with python3.5 and 3.6, and aiohttp 3.3.2.
Starting from version 3.0 aiohttp converted send_str
into a coroutine. Install aiohttp==2.3.10
and you'll be good to go.
I tried to fix this by applying await before ws.send_str and converting on_master_output
into an async function. But in loop.add_reader(p_out, on_master_output)
add_reader
doesn't allow the callback to be async.
I would be happy to hear suggestions on how to update the example.
I've fixed that by changing ws.send_str...
in on_master_output
to asyncio.ensure_future(ws.send_str(terminal.dumps()))
.
The more-preferred-now version asyncio.create_task(ws.send_str(terminal.dumps()))
should also work.