amsatop packageο
Libraryο
amsatop package.
Exposes top-level components for creating your own htop
- class amsatop.Htop(proc_folder: str = '/proc')[source]ο
Bases:
ABCAbstract 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:
HtopMock 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.
- class amsatop.Process(pid: int, command: str, type: TaskType, priority: int | None)[source]ο
Bases:
objectImmutable 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ο
- class amsatop.TaskType(*values)[source]ο
Bases:
EnumEnumeration 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ο
- amsatop.utils package
- Module contents
StatFileStatFile.cmajfltStatFile.cminfltStatFile.commandStatFile.cstimeStatFile.cutimeStatFile.flagsStatFile.from_stat_line()StatFile.majfltStatFile.minfltStatFile.niceStatFile.num_threadsStatFile.pgrpStatFile.pidStatFile.ppidStatFile.priorityStatFile.sessionStatFile.starttimeStatFile.stateStatFile.stimeStatFile.tpgidStatFile.tty_nrStatFile.utime
StatusFileStatusFile.CapAmbStatusFile.CapBndStatusFile.CapEffStatusFile.CapInhStatusFile.CapPrmStatusFile.CoreDumpingStatusFile.Cpus_allowedStatusFile.Cpus_allowed_listStatusFile.FDSizeStatusFile.GidStatusFile.GroupsStatusFile.HugetlbPagesStatusFile.KthreadStatusFile.Mems_allowedStatusFile.Mems_allowed_listStatusFile.NSpgidStatusFile.NSpidStatusFile.NSsidStatusFile.NStgidStatusFile.NameStatusFile.NgidStatusFile.NoNewPrivsStatusFile.PPidStatusFile.PidStatusFile.RssAnonStatusFile.RssFileStatusFile.RssShmemStatusFile.SeccompStatusFile.Seccomp_filtersStatusFile.ShdPndStatusFile.SigBlkStatusFile.SigCgtStatusFile.SigIgnStatusFile.SigPndStatusFile.SigQStatusFile.SpeculationIndirectBranchStatusFile.Speculation_Store_BypassStatusFile.StateStatusFile.THP_enabledStatusFile.TgidStatusFile.ThreadsStatusFile.TracerPidStatusFile.UidStatusFile.UmaskStatusFile.VmDataStatusFile.VmExeStatusFile.VmHWMStatusFile.VmLckStatusFile.VmLibStatusFile.VmPTEStatusFile.VmPeakStatusFile.VmPinStatusFile.VmRSSStatusFile.VmSizeStatusFile.VmStkStatusFile.VmSwapStatusFile.from_lines()StatusFile.nonvoluntary_ctxt_switchesStatusFile.untag_maskStatusFile.voluntary_ctxt_switchesStatusFile.x86_Thread_featuresStatusFile.x86_Thread_features_locked
get_stat_file_from_path()get_status_file_from_path()
- Module contents