Advertisement
tagercito

Untitled

Apr 1st, 2020
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import asyncio
  2. from contextlib import suppress
  3.  
  4.  
  5. async def echo_forever():
  6. while True:
  7. print("echo")
  8. await asyncio.sleep(1)
  9.  
  10. @asyncio.coroutine
  11. async def echo(reader, writer):
  12. print('client connected')
  13.  
  14. def main(loop):
  15. asyncio.ensure_future(echo_forever()) # fire and forget
  16. coro = asyncio.start_server(echo, '127.0.0.1', 8889, loop=loop)
  17. server = loop.run_until_complete(coro)
  18.  
  19.  
  20. if __name__ == '__main__':
  21. loop = asyncio.get_event_loop()
  22. main(loop)
  23. # Let's also cancel all running tasks:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement