diff --git a/verified_cogen/tools/verifier.py b/verified_cogen/tools/verifier.py index 1873d13..274a14b 100644 --- a/verified_cogen/tools/verifier.py +++ b/verified_cogen/tools/verifier.py @@ -1,4 +1,6 @@ import logging +import os +import signal import subprocess from pathlib import Path from typing import Optional @@ -13,19 +15,13 @@ def __init__(self, shell: str, verifier_cmd: str, timeout: int = 60): self.timeout = timeout def verify(self, file_path: Path) -> Optional[tuple[bool, str, str]]: + proc = subprocess.Popen( + [self.shell, "-i", "-l", "-c", f'{self.verifier_cmd} "{file_path}"'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) try: - res = subprocess.run( - '{} -i -l -c "{} "{}""; exit'.format( - self.shell, self.verifier_cmd, file_path - ), - capture_output=True, - shell=True, - timeout=self.timeout, - ) + out, err = proc.communicate(timeout=self.timeout) + return proc.returncode == 0, out.decode(), err.decode() except subprocess.TimeoutExpired: - return None - return ( - res.returncode == 0, - res.stdout.decode("utf-8"), - res.stderr.decode("utf-8"), - ) + os.killpg(os.getpgid(proc.pid), signal.SIGTERM)