Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- from contextlib import suppress
- async def echo_forever():
- while True:
- print("echo")
- await asyncio.sleep(1)
- @asyncio.coroutine
- async def echo(reader, writer):
- print('client connected')
- def main(loop):
- asyncio.ensure_future(echo_forever()) # fire and forget
- coro = asyncio.start_server(echo, '127.0.0.1', 8889, loop=loop)
- server = loop.run_until_complete(coro)
- if __name__ == '__main__':
- loop = asyncio.get_event_loop()
- main(loop)
- # Let's also cancel all running tasks:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement