diff --git a/spalloc_client/_utils.py b/spalloc_client/_utils.py index 7ac6fab22..8c9cf802e 100644 --- a/spalloc_client/_utils.py +++ b/spalloc_client/_utils.py @@ -17,6 +17,10 @@ from typing import Optional +def time_left_float(timestamp: float) -> float: + return max(0.0, timestamp - time.time()) + + def time_left(timestamp: Optional[float]) -> Optional[float]: """ Convert a timestamp into how long to wait for it. """ diff --git a/spalloc_client/job.py b/spalloc_client/job.py index 9ef4b1e55..164101529 100644 --- a/spalloc_client/job.py +++ b/spalloc_client/job.py @@ -32,7 +32,7 @@ from .protocol_client import ProtocolClient, ProtocolTimeoutError from .spalloc_config import SpallocConfig, SEARCH_PATH from .states import JobState -from ._utils import time_left, timed_out, make_timeout +from ._utils import time_left, time_left_float, timed_out, make_timeout logger = logging.getLogger(__name__) @@ -249,8 +249,8 @@ def __init__(self, *args: int, **kwargs: Union[float, str, None]): hostname = cast(str, kwargs.get("hostname", config.hostname)) owner = kwargs.get("owner", config.owner) port = cast(int, kwargs.get("port", config.port)) - self._reconnect_delay = kwargs.get("reconnect_delay", - config.reconnect_delay) + self._reconnect_delay = cast(float, kwargs.get("reconnect_delay", + config.reconnect_delay)) self._timeout = cast(float, kwargs.get("timeout", config.timeout)) if hostname is None: raise ValueError("A hostname must be specified.") @@ -671,7 +671,7 @@ def _do_reconnect(self, finish_time: Optional[float]) -> None: """ self._client.close() if finish_time is not None: - delay = min(time_left(finish_time), self._reconnect_delay) + delay = min(time_left_float(finish_time), self._reconnect_delay) else: delay = self._reconnect_delay time.sleep(max(0.0, delay)) diff --git a/spalloc_client/scripts/job.py b/spalloc_client/scripts/job.py index ec80177c6..8022c17e4 100644 --- a/spalloc_client/scripts/job.py +++ b/spalloc_client/scripts/job.py @@ -86,6 +86,7 @@ Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES) from spalloc_client import ProtocolClient from spalloc_client._utils import render_timestamp +from spalloc_client.spalloc_config import SpallocConfig from spalloc_client.scripts.support import Terminate, Script @@ -340,7 +341,7 @@ def get_job_id(self, client: ProtocolClient, return cast(int, job_ids[0]) @overrides(Script.get_parser) - def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser: + def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description="Manage running jobs.") parser.add_argument( diff --git a/spalloc_client/scripts/machine.py b/spalloc_client/scripts/machine.py index 5da62d6fa..fa1deb76c 100644 --- a/spalloc_client/scripts/machine.py +++ b/spalloc_client/scripts/machine.py @@ -38,6 +38,7 @@ from spinn_utilities.typing.json import JsonObject, JsonObjectArray from spalloc_client import __version__, ProtocolClient +from spalloc_client.spalloc_config import SpallocConfig from spalloc_client.term import ( Terminal, render_table, render_definitions, render_boards, render_cells, DEFAULT_BOARD_EDGES, TableRow, TableType) @@ -257,7 +258,7 @@ def get_and_display_machine_info( show_machine(t, machines, jobs, args.machine, not args.detailed) @overrides(Script.get_parser) - def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser: + def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description="Get the state of individual machines.") parser.add_argument( diff --git a/spalloc_client/scripts/ps.py b/spalloc_client/scripts/ps.py index 7abe9f458..3cb094af6 100644 --- a/spalloc_client/scripts/ps.py +++ b/spalloc_client/scripts/ps.py @@ -33,6 +33,7 @@ from spinn_utilities.typing.json import JsonObjectArray from spalloc_client import __version__, JobState, ProtocolClient +from spalloc_client.spalloc_config import SpallocConfig from spalloc_client.term import Terminal, render_table, TableColumn, TableType from spalloc_client._utils import render_timestamp from .support import Script @@ -128,7 +129,7 @@ class ProcessListScript(Script): An object form Job scripts. """ @overrides(Script.get_parser) - def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser: + def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser: parser = argparse.ArgumentParser(description="List all active jobs.") parser.add_argument( "--version", "-V", action="version", version=__version__) diff --git a/spalloc_client/scripts/where_is.py b/spalloc_client/scripts/where_is.py index bca63567a..3c4885cf6 100644 --- a/spalloc_client/scripts/where_is.py +++ b/spalloc_client/scripts/where_is.py @@ -72,8 +72,8 @@ from spalloc_client import __version__, ProtocolClient from spalloc_client.term import render_definitions - from spalloc_client.scripts.support import Terminate, Script +from spalloc_client.spalloc_config import SpallocConfig class WhereIsScript(Script): @@ -88,7 +88,7 @@ def __init__(self) -> None: self.show_board_chip = False @overrides(Script.get_parser) - def get_parser(self, cfg: Dict[str, str]) -> argparse.ArgumentParser: + def get_parser(self, cfg: SpallocConfig) -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description="Find out the location (physical or logical) of a " "chip or board.")