dlvhex2.py 文件源码

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

项目:py-aspio 作者: hexhex 项目源码 文件源码
def __iter__(self) -> Iterator[str]:
        '''Return an iterator over the lines written to stdout. May only be called once! Might raise a SolverSubprocessError.'''
        assert not self.iterating, 'You may only iterate once over a single DlvhexLineReader instance.'
        self.iterating = True
        # Requirement: dlvhex2 needs to flush stdout after every line
        with io.TextIOWrapper(self.process.stdout, encoding=self.stdout_encoding) as stdout_lines:
            for line in stdout_lines:
                yield line
                # Tell dlvhex2 to prepare the next answer set
                if not self.process.stdin.closed:
                    self.process.stdin.write(b'\n')
                    self.process.stdin.flush()
                else:
                    break
        # We've exhausted stdout, so either:
        #   1. we got all answer sets, or
        #   2. an error occurred,
        # and dlvhex closed stdout (and probably terminated).
        # Give it a chance to terminate gracefully.
        try:
            self.process.wait(timeout=0.005)  # type: ignore (mypy does not know about `timeout`)
        except subprocess.TimeoutExpired:  # type: ignore (mypy does not know about `TimeoutExpired`)
            pass
        self.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号