Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #! /usr/bin/env python3
  2.  
  3. import asyncio
  4. import logging
  5.  
  6. async def read_one(reader):
  7.     await asyncio.wait_for(reader.read(1), timeout=None)
  8.  
  9.  
  10. async def main():
  11.     reader, writer = await asyncio.open_connection(host="ya.ru", port="80")
  12.     try:
  13.         await asyncio.wait_for(read_one(reader), timeout=0.1)
  14.     except Exception as e:
  15.         logging.critical("got exception: %r", e)
  16.     try:
  17.         await read_one(reader)
  18.     except Exception as e:
  19.         logging.critical("got exception: %r", e)
  20.  
  21.  
  22. logging.basicConfig(level=logging.DEBUG,
  23.                     format="%(asctime)s - %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s")
  24.  
  25. asyncio.get_event_loop().run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement