Skip to content

Commit

Permalink
Better timeout handling (#111)
Browse files Browse the repository at this point in the history
* Implement a better timeout handling

* fix lint

* Add debug output
  • Loading branch information
pvizeli authored Jul 7, 2020
1 parent fdc6bbb commit a823ae0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 30 deletions.
28 changes: 6 additions & 22 deletions builder/pip.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Pip build commands."""
import os
import subprocess
import sys
from pathlib import Path
from typing import List, Optional

from .utils import run_command


def build_wheels_package(
package: str,
Expand All @@ -24,12 +24,8 @@ def build_wheels_package(
# Add constraint
constraint_cmd = f"--constraint {constraint}" if constraint else ""

subprocess.run(
run_command(
f'pip3 wheel --progress-bar off --no-binary "{skip_binary}" --wheel-dir {output} --find-links {index} {constraint_cmd} "{package}"',
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
env=build_env,
timeout=timeout,
)
Expand All @@ -53,12 +49,8 @@ def build_wheels_requirement(
# Add constraint
constraint_cmd = f"--constraint {constraint}" if constraint else ""

subprocess.run(
run_command(
f'pip3 wheel --progress-bar off --no-binary "{skip_binary}" --wheel-dir {output} --find-links {index} {constraint_cmd} --requirement {requirement}',
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
env=build_env,
timeout=timeout,
)
Expand All @@ -72,12 +64,8 @@ def build_wheels_local(index: str, output: Path) -> None:
build_env = os.environ.copy()
build_env["MAKEFLAGS"] = f"-j{cpu}"

subprocess.run(
run_command(
f"pip3 wheel --progress-bar off --wheel-dir {output} --find-links {index} .",
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
env=build_env,
)

Expand Down Expand Up @@ -118,10 +106,6 @@ def install_pips(index: str, pips: str) -> None:
"""Install all pipy string formated as 'package1;package2'."""
packages = " ".join(pips.split(";"))

subprocess.run(
run_command(
f"pip install --progress-bar off --upgrade --no-cache-dir --prefer-binary --find-links {index} {packages}",
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
)
10 changes: 3 additions & 7 deletions builder/upload/rsync.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"""Upload plugin rsync."""
from pathlib import Path
import subprocess
import sys

from ..utils import run_command


def upload(local: Path, remote: str) -> None:
"""Upload wheels from folder to remote rsync server."""
subprocess.run(
run_command(
f"rsync --human-readable --recursive --partial --progress --checksum {local}/* {remote}/",
shell=True,
check=True,
stdout=sys.stdout,
stderr=sys.stderr,
)
26 changes: 26 additions & 0 deletions builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from pathlib import Path
import os
import re
import subprocess
import sys
from typing import Optional, Dict

import requests

Expand Down Expand Up @@ -33,3 +36,26 @@ def fix_wheels_name(wheels_folder: Path) -> None:
if not match:
continue
package.rename(Path(package.parent, f"{match.group('name')}none-any.whl"))


def run_command(
cmd: str, env: Optional[Dict[str, str]] = None, timeout: Optional[int] = None
) -> None:
"""Implement subprocess.run but handle timeout different."""
process = subprocess.Popen(
cmd, shell=True, stdout=sys.stdout, stderr=sys.stderr, env=env
)

# Run command and wait
try:
process.communicate(timeout=timeout)
except subprocess.TimeoutExpired as err:
print(f"Timeout for '{cmd}'", flash=True)
process.kill()
raise err

# Process return code
if process.returncode == 0:
return
print(f"Command '{cmd}' return error {process.returncode}", flash=True)
raise subprocess.CalledProcessError(process.returncode, cmd)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "1.12.0"
VERSION = "1.12.1"

setup(
name="builder",
Expand Down

0 comments on commit a823ae0

Please sign in to comment.