diff --git a/examples/client_ws.py b/examples/client_ws.py index f4e7e1e8ca0..74505170edb 100755 --- a/examples/client_ws.py +++ b/examples/client_ws.py @@ -14,12 +14,9 @@ from asyncio import selectors -def start_client(loop, url): +async def start_client(loop, url): name = input('Please enter your name: ') - # send request - ws = yield from aiohttp.ws_connect(url, autoclose=False, autoping=False) - # input reader def stdin_callback(): line = sys.stdin.buffer.readline().decode('utf-8') @@ -51,7 +48,9 @@ async def dispatch(): break - yield from dispatch() + # send request + async with aiohttp.ws_connect(url, autoclose=False, autoping=False) as ws: + await dispatch() ARGS = argparse.ArgumentParser( @@ -71,9 +70,8 @@ async def dispatch(): url = 'http://{}:{}'.format(args.host, args.port) - loop = asyncio.SelectorEventLoop(selectors.SelectSelector()) - asyncio.set_event_loop(loop) + loop = asyncio.get_event_loop() loop.add_signal_handler(signal.SIGINT, loop.stop) - asyncio.Task(start_client(loop, url)) + loop.create_task(start_client(loop, url)) loop.run_forever()