test_subprocess_partial_info.py 文件源码

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

项目:HORD 作者: ilija139 项目源码 文件源码
def handle_eval(self, record):
        self.process = Popen(['./sumfun_ext', array2str(record.params[0])],
                             stdout=PIPE)

        val = np.nan
        # Continuously check for new outputs from the subprocess
        while True:
            output = self.process.stdout.readline()
            if output == '' and self.process.poll() is not None:  # No new output
                break
            if output:  # New intermediate output
                try:
                    val = float(output.strip())  # Try to parse output
                    if val > 350:  # Terminate if too large
                        self.process.terminate()
                        self.finish_success(record, 350)
                        return
                except ValueError:  # If the output is nonsense we terminate
                    logging.warning("Incorrect output")
                    self.process.terminate()
                    self.finish_failure(record)
                    return

        rc = self.process.poll()  # Check the return code
        if rc < 0 or np.isnan(val):
            logging.warning("Incorrect output or crashed evaluation")
            self.finish_failure(record)
        else:
            self.finish_success(record, val)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号