geckordp.utils module

class geckordp.utils.ExpireAt(sec: float)

Bases: object

expired()
expired_time()
geckordp.utils.find_free_ports(n=1) List[int]

Searches for free ports to use.

Note

It can’t be guaranteed that the returned ports stay free. However it is very unlikely it happens in real-world situations as long the operating system doesn’t allocate and free ports all the time.

Parameters:

n (int, optional) – The amount of free ports to search. Defaults to 1.

Returns:

A list of free ports.

Return type:

List[int]

geckordp.utils.kill(proc: Popen) bool

Kill a process by handle.

Parameters:

proc (subprocess.Popen) – The process handle.

Returns:

True: if successful terminated, False: failed to terminate process.

Return type:

bool

geckordp.utils.kill_by_pid(pid: int) bool

Kill a process by handle.

Parameters:

pid (int) – The process ID.

Returns:

True: if successful terminated, False: failed to terminate process.

Return type:

bool

geckordp.utils.wait_dir_changed(path: Path, timeout_sec=20.0, check_sec=0.3, min_file_age_sec=8.0, ignore_files: list | None = None) bool

Waits for the latest file modification in a path to reach a specified age in seconds.

Parameters:
  • path (Path) – The input path to check for file modifications.

  • timeout_sec (float, optional) – Maximum wait time. Defaults to 20.0.

  • check_sec (float, optional) – Interval between the probes. Defaults to 0.3.

  • min_file_age_sec (float, optional) – Minimum file age. Defaults to 8.0.

  • ignore_files (list, optional) – Ignore a file if it contains a keyword in this list. Defaults to None.

Raises:

ValueError – If ‘min_file_age_sec’ is greater or equal than ‘timeout_sec’.

Returns:

True: if successful waited, False: on timeout.

Return type:

bool

geckordp.utils.wait_process_loaded(pid: int, timeout_sec=15.0, check_sec=0.3, no_activity_threshold=9.0, no_activity_min_count=6) bool

Waits for a process til cpu activity settles down.

Parameters:
  • pid (int) – The process ID.

  • timeout_sec (float, optional) – Maximum wait time. Defaults to 15.0.

  • check_sec (float, optional) – Interval between the measurements. Defaults to 0.3.

  • no_activity_threshold (float, optional) – The percentage threshold which sets the activity as low. Defaults to 9.0.

  • no_activity_min_count (int, optional) – The minimum amount to break on low activity. Defaults to 6.

Returns:

True: if successful waited, False: failed to wait for process.

Return type:

bool