Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiyu Yang committed Apr 15, 2024
1 parent b1dc684 commit 8cf0a7b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"python-dotenv",
"loguru",
"filelock",
"psutil",
"tqdm",
"toml",
"types-toml",
Expand Down
2 changes: 0 additions & 2 deletions src/lean_dojo/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def run_interactive(
universal_newlines=True,
encoding="utf-8",
bufsize=1,
preexec_fn=os.setpgrp,
)

return proc
Expand Down Expand Up @@ -342,7 +341,6 @@ def run_interactive(
universal_newlines=True,
encoding="utf-8",
bufsize=1,
preexec_fn=os.setpgrp,
)
return proc

Expand Down
29 changes: 13 additions & 16 deletions src/lean_dojo/interaction/dojo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time
import signal
import shutil
import psutil
from pathlib import Path
from loguru import logger
from tempfile import mkdtemp
Expand Down Expand Up @@ -100,21 +101,10 @@ class DojoInitError(Exception):
pass


def _get_all_dependencies(
root_dir: Path, lean_path: Path, repo: LeanGitRepo
) -> List[Path]:
all_deps = []
stack = [lean_path]

while stack != []:
json_path = to_json_path(root_dir, stack.pop(), repo)
tf = TracedFile.from_traced_file(root_dir, json_path, repo)
for _, d in tf.get_direct_dependencies(repo):
if d not in all_deps:
all_deps.append(d)
stack.append(d)

return all_deps
def _kill_descendants(proc: psutil.Process) -> None:
for child in proc.children():
_kill_descendants(child)
proc.kill()


class Dojo:
Expand Down Expand Up @@ -315,7 +305,14 @@ def _cleanup_container(self) -> None:
def _cleanup_proc(self) -> None:
"""Clean up the subprocess."""
logger.debug(f"Cleaning up the subprocess {self.proc.pid}.")
os.killpg(os.getpgid(self.proc.pid), signal.SIGKILL)
_kill_descendants(psutil.Process(self.proc.pid))
"""
self.proc.terminate()
try:
self.proc.wait(timeout=0.5)
except TimeoutExpired:
self.proc.kill()
"""

def _cleanup_tmp_dir(self) -> None:
"""Clean up the temporary directory."""
Expand Down

0 comments on commit 8cf0a7b

Please sign in to comment.