Skip to content

Commit

Permalink
timeout is a float
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-B committed Nov 26, 2024
1 parent 76ca52a commit fdd75f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
8 changes: 4 additions & 4 deletions spalloc_client/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ def __init__(self, *args: int, **kwargs: Union[float, str, None]):
config = SpallocConfig(config_filenames)

# Get protocol client options
hostname = kwargs.get("hostname", config.hostname)
hostname = cast(str, kwargs.get("hostname", config.hostname))
owner = kwargs.get("owner", config.owner)
port = kwargs.get("port", config.port)
port = cast(int, kwargs.get("port", config.port))
self._reconnect_delay = kwargs.get("reconnect_delay",
config.reconnect_delay)
self._timeout = kwargs.get("timeout", config.timeout)
self._timeout = cast(float, kwargs.get("timeout", config.timeout))
if hostname is None:
raise ValueError("A hostname must be specified.")

Expand Down Expand Up @@ -677,7 +677,7 @@ def _do_reconnect(self, finish_time: Optional[float]) -> None:
time.sleep(max(0.0, delay))
self._reconnect()

def wait_until_ready(self, timeout: Optional[int] = None) -> None:
def wait_until_ready(self, timeout: Optional[float] = None) -> None:
""" Block until the job is allocated and ready.
Parameters
Expand Down
35 changes: 18 additions & 17 deletions spalloc_client/protocol_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import json
import socket
from types import TracebackType
from typing import cast, Dict, Literal, Optional, Type, Union
from typing import Any, cast, Dict, List, Literal, Optional, Type, Union
from threading import current_thread, RLock, local, Thread

from typing_extensions import Self
Expand Down Expand Up @@ -281,7 +281,7 @@ def _send_json(

def call(self, name: str, timeout: Optional[float],
*args: Union[int, str, None],
**kwargs: JsonValue) -> JsonValue:
**kwargs: Any) -> JsonValue:
""" Send a command to the server and return the reply.
Parameters
Expand Down Expand Up @@ -376,11 +376,12 @@ def wait_for_notification(
# The bindings of the Spalloc protocol methods themselves; simplifies use
# from IDEs.

def version(self, timeout: Optional[int] = None) -> str:
def version(self, timeout: Optional[float] = None) -> str:
""" Ask what version of spalloc is running. """
return cast(str, self.call("version", timeout))

def create_job(self, *args: int, **kwargs: str) -> int:
def create_job(self, *args: int,
**kwargs: Union[float, str, List[str], None]) -> int:
"""
Start a new job
"""
Expand All @@ -400,55 +401,55 @@ def job_keepalive(self, job_id: int,
return cast(dict, self.call("job_keepalive", timeout, job_id))

def get_job_state(self, job_id: int,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
"""Get the state for this job """
return cast(dict, self.call("get_job_state", timeout, job_id))

def get_job_machine_info(self, job_id: int,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Get info for this job. """
return cast(dict, self.call("get_job_machine_info", timeout, job_id))

def power_on_job_boards(self, job_id: int,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn on the power on the jobs boards. """
return cast(dict, self.call("power_on_job_boards", timeout, job_id))

def power_off_job_boards(self, job_id: int,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn off the power on the jobs boards. """
return cast(dict, self.call("power_off_job_boards", timeout, job_id))

def destroy_job(self, job_id: int, reason: Optional[str] = None,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Destroy the job """
return cast(dict, self.call("destroy_job", timeout,
job_id, reason=reason))

def notify_job(self, job_id: Optional[int] = None,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn on notification of job status changes. """
return cast(dict, self.call("notify_job", timeout, job_id))

def no_notify_job(self, job_id: Optional[int] = None,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn off notification of job status changes. """
return cast(dict, self.call("no_notify_job", timeout,
job_id))

def notify_machine(self, machine_name: Optional[str] = None,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn on notification of machine status changes. """
return cast(dict, self.call("notify_machine", timeout,
machine_name))

def no_notify_machine(self, machine_name: Optional[str] = None,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Turn off notification of machine status changes. """
return cast(dict, self.call("no_notify_machine", timeout,
machine_name))

def list_jobs(self, timeout: Optional[int] = None) -> JsonObjectArray:
def list_jobs(self, timeout: Optional[float] = None) -> JsonObjectArray:
""" Obtains a list of jobs currently running. """
return cast(list, self.call("list_jobs", timeout))

Expand All @@ -459,14 +460,14 @@ def list_machines(self,

def get_board_position(
self, machine_name: str, x: int, y: int, z: int,
timeout: Optional[int] = None) -> JsonObject: # pragma: no cover
timeout: Optional[float] = None) -> JsonObject: # pragma: no cover
""" Gets the position of board x, y, z on the given machine. """
# pylint: disable=too-many-arguments
return cast(dict, self.call("get_board_position", timeout,
machine_name, x, y, z))

def get_board_at_position(self, machine_name: str, x: int, y: int, z: int,
timeout: Optional[int] = None
timeout: Optional[float] = None
) -> JsonObject: # pragma: no cover
""" Gets the board x, y, z on the requested machine. """
# pylint: disable=too-many-arguments
Expand All @@ -480,7 +481,7 @@ def get_board_at_position(self, machine_name: str, x: int, y: int, z: int,
frozenset("job_id chip_x chip_y".split())])

def where_is(self, job_id: int, chip_x: int, chip_y: int,
timeout: Optional[int] = None) -> JsonObject:
timeout: Optional[float] = None) -> JsonObject:
""" Reports where ion the Machine a job is running """
# Test for whether sane arguments are passed.
return cast(dict, self.call("where_is", timeout, job_id=job_id,
Expand Down
10 changes: 5 additions & 5 deletions spalloc_client/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _state_name(mapping: JsonObject) -> str:
return state.name # pylint: disable=no-member


def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[int],
def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[float],
job_id: int) -> None:
""" Print a human-readable overview of a Job's attributes.
Expand Down Expand Up @@ -173,7 +173,7 @@ def show_job_info(t: Terminal, client: ProtocolClient, timeout: Optional[int],
print(render_definitions(info))


def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[int],
def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[float],
job_id: int) -> int:
""" Re-print a job's information whenever the job changes.
Expand Down Expand Up @@ -207,7 +207,7 @@ def watch_job(t: Terminal, client: ProtocolClient, timeout: Optional[int],
print("")


def power_job(client: ProtocolClient, timeout: Optional[int],
def power_job(client: ProtocolClient, timeout: Optional[float],
job_id: int, power: bool) -> None:
""" Power a job's boards on/off and wait for the action to complete.
Expand Down Expand Up @@ -256,7 +256,7 @@ def power_job(client: ProtocolClient, timeout: Optional[int],
f"job {job_id} in state {_state_name(state)}"))


def list_ips(client: ProtocolClient, timeout: Optional[int],
def list_ips(client: ProtocolClient, timeout: Optional[float],
job_id: int) -> None:
""" Print a CSV of board hostnames for all boards allocated to a job.
Expand Down Expand Up @@ -289,7 +289,7 @@ def list_ips(client: ProtocolClient, timeout: Optional[int],
print(f"{x},{y},{hostname}")


def destroy_job(client: ProtocolClient, timeout: Optional[int],
def destroy_job(client: ProtocolClient, timeout: Optional[float],
job_id: int, reason: Optional[str] = None) -> None:
""" Destroy a running job.
Expand Down
2 changes: 1 addition & 1 deletion spalloc_client/scripts/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def exit(self) -> None:
sys.exit(self._code)


def version_verify(client: ProtocolClient, timeout: Optional[int]) -> None:
def version_verify(client: ProtocolClient, timeout: Optional[float]) -> None:
"""
Verify that the current version of the client is compatible
"""
Expand Down

0 comments on commit fdd75f7

Please sign in to comment.