Skip to content

Commit

Permalink
terminate process group on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
WeetHet committed Sep 17, 2024
1 parent cf35ce5 commit f1b0f12
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions verified_cogen/tools/verifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import os
import signal
import subprocess
from pathlib import Path
from typing import Optional
Expand All @@ -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)

0 comments on commit f1b0f12

Please sign in to comment.