protocol.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:bt 作者: kracekumar 项目源码 文件源码
def __anext__(self):
        # Read data from the socket. When we have enough data to parse, parse
        # it and return the message. Until then keep reading from stream
        while True:
            try:
                if self.buffer:
                    message = self.parse()
                    if message:
                        return message
                logger.debug('I m stuck at reading from socket')
                data = await self.reader.read(
                    PeerStreamIterator.CHUNK_SIZE)
                if data:
                    self.buffer += data
                    message = self.parse()
                    if message:
                        return message
            except ConnectionResetError:
                logging.debug('Connection closed by peer')
                raise StopAsyncIteration()
            except CancelledError:
                raise StopAsyncIteration()
            except StopAsyncIteration as e:
                # Cath to stop logging
                raise e
            except Exception:
                logging.exception('Error when iterating over stream!')
                raise StopAsyncIteration()
        raise StopAsyncIteration()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号