Skip to content

Commit

Permalink
Killing timeouted processes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicz committed May 8, 2018
1 parent bda9390 commit f821783
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 6 additions & 4 deletions arca/backend/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
stderr=subprocess.PIPE,
cwd=cwd)

out_stream, err_stream = process.communicate(timeout=task.timeout)
try:
out_stream, err_stream = process.communicate(timeout=task.timeout)
except subprocess.TimeoutExpired:
process.kill()
raise BuildTimeoutError(f"The task timeouted after {task.timeout} seconds.")

out_output = out_stream.decode("utf-8")
err_output = err_stream.decode("utf-8")
Expand All @@ -174,9 +178,7 @@ def run(self, repo: str, branch: str, task: Task, git_repo: Repo, repo_path: Pat
logger.debug(out_output)

return Result(out_output)
except subprocess.TimeoutExpired:
raise BuildTimeoutError(f"The task timeouted after {task.timeout} seconds.")
except BuildError: # can be raised by :meth:`Result.__init__`
except BuildError: # can be raised by :meth:`Result.__init__` or by timeout
raise
except Exception as e:
logger.exception(e)
Expand Down
1 change: 1 addition & 0 deletions arca/backend/current_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def install_requirements(self, *, path: Optional[Path] = None, requirements: Opt
try:
out_stream, err_stream = process.communicate(timeout=self.requirements_timeout)
except subprocess.TimeoutExpired:
process.kill()
raise BuildTimeoutError(f"Installing of requirements timeouted after {self.requirements_timeout} seconds.")

out_stream = out_stream.decode("utf-8")
Expand Down
1 change: 1 addition & 0 deletions arca/backend/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def get_or_create_venv(self, path: Path) -> Path:
try:
out_stream, err_stream = process.communicate(timeout=self.requirements_timeout)
except subprocess.TimeoutExpired:
process.kill()
shutil.rmtree(venv_path, ignore_errors=True)

raise BuildTimeoutError(f"Installing of requirements timeouted after "
Expand Down

0 comments on commit f821783

Please sign in to comment.