selectel / pyte

Simple VTXXX-compatible linux terminal emulator
http://pyte.readthedocs.org/
GNU Lesser General Public License v3.0
653 stars 101 forks source link

Example webterm.py fails, send_str never awaited. #122

Open ilar opened 6 years ago

ilar commented 6 years ago

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.

kyrgyz-nlp commented 5 years ago

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.

positron96 commented 1 year ago

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.