amsatop package

Library

amsatop package.

Exposes top-level components for creating your own htop

class amsatop.Htop(proc_folder: str = '/proc')[source]

Bases: ABC

Abstract base class representing a simplified version of the Unix β€˜htop’ utility.

This class defines the interface for interacting with system process information. It is designed to be subclassed by students or developers who will provide concrete implementations for the defined methods.

proc_folder

Path to the directory containing process information. Defaults to β€œ/proc”, but can be overridden by setting the β€œPROC_FOLDER” environment variable. You should allways use this variable and not β€œ/proc”.

Type:

str

abstractmethod get_hup() List[Process][source]

Retrieve processes that are eligible to ignore the SIGHUP signal.

Returns:

A list of Process objects that ignore the SIGHUP signal.

Raises:

NotImplementedError: If not implemented by subclass.

abstractmethod get_priorities() List[Process][source]

Retrieve all system processes along with their scheduling priorities.

Returns:

A list of Process objects with priority information.

Raises:

NotImplementedError: If not implemented by subclass.

abstractmethod get_processes() List[Process][source]

Retrieve all system processes, without the priority field

Returns:

A list of Process objects representing all running processes.

Raises:

NotImplementedError – If not implemented by subclass.

proc_folder: str
class amsatop.HtopMock(proc_folder: str = '/proc')[source]

Bases: Htop

Mock implementation of the Htop interface for testing or demonstration purposes.

This class simulates process information by returning hardcoded Process instances. Each method (get_processes, get_priorities, get_hup) returns a random subset of predefined mock processes.

Useful for testing code that depends on Htop without requiring access to the actual system process tree.

RETURN_PROCESSES = 5
get_hup() list[Process][source]

Retrieve processes that are eligible to ignore the SIGHUP signal.

Returns:

A list of Process objects that ignore the SIGHUP signal.

Raises:

NotImplementedError: If not implemented by subclass.

get_priorities() list[Process][source]

Retrieve all system processes along with their scheduling priorities.

Returns:

A list of Process objects with priority information.

Raises:

NotImplementedError: If not implemented by subclass.

get_processes() list[Process][source]

Retrieve all system processes, without the priority field

Returns:

A list of Process objects representing all running processes.

Raises:

NotImplementedError – If not implemented by subclass.

class amsatop.Process(pid: int, command: str, type: TaskType, priority: int | None)[source]

Bases: object

Immutable data class representing a system process.

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

  • command (str) – The command or executable that launched the process.

  • type (TaskType) – The type of the process

  • priority (int | None) – The scheduling priority of the process. Can be None if unavailable or you’re doing Prac-2.1 .

command: str
pid: int
priority: int | None
type: TaskType
class amsatop.TaskType(*values)[source]

Bases: Enum

Enumeration of tasks types.

KTHREAD = 'kthread'
PROCESS = 'process'
THREAD = 'thread'
amsatop.run_ui(htop: Htop = None, refresh: int = 2) None[source]

Given an instance of htop, run the tui interface. By default, if no parameter is given, it launches the HtopMock implementation.

Parameters:
  • htop – An instance of your htop implementation

  • refresh – The seconds between each table refresh, 2 by default

Utilities