Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- import asyncio
- import logging
- async def read_one(reader):
- await asyncio.wait_for(reader.read(1), timeout=None)
- async def main():
- reader, writer = await asyncio.open_connection(host="ya.ru", port="80")
- try:
- await asyncio.wait_for(read_one(reader), timeout=0.1)
- except Exception as e:
- logging.critical("got exception: %r", e)
- try:
- await read_one(reader)
- except Exception as e:
- logging.critical("got exception: %r", e)
- logging.basicConfig(level=logging.DEBUG,
- format="%(asctime)s - %(filename)s:%(lineno)d - %(funcName)s() - %(levelname)s - %(message)s")
- asyncio.get_event_loop().run_until_complete(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement