Skip to main content

A Python library to manage system processes and gather system information.

Project description

PyTaskMGR

A Python library that allows you to interact with processes and the system.

Installation

To install PyTaskMGR, you can use pip:

pip install pytaskmgr

Examples:

Terminating a process

from pytaskmgr.process import Process
pid = 69420
image_name = "example.exe"
proc = Process(image_name, pid)
proc.terminate(force=True)

Creating a process

from pytaskmgr.process import create_process
proc = create_process("example.exe")
# ...and then you can terminate it that way!
proc.terminate(force=True)

Suspending a process (pausing)

from pytaskmgr.process import Process
pid = 69420
image_name = "example.exe"
proc = Process(image_name, pid)
proc.suspend(delay=1, stop=5) # Suspends after 1 second and resumes the process after 5 seconds.
# resume it
proc.resume()

Restarting a process

from pytaskmgr.process import Process
pid = 69420
image_name = "example.exe"
proc = Process(image_name, pid)
proc.restart(force=True)

or

from pytaskmgr.process import Process
pid = 69420
image_name = "example.exe"
proc = Process(image_name, pid)
proc.terminate(force=True)
create_process(image_name)
# Not recommended because the process might not fully clean its cache or temporary/in-memory files.

Getting a process ID by using its name

from pytaskmgr.process import Process
image_name = "example.exe"
proc = Process(image_name)
# Get the process ID
pid = proc.get_pid()
# Returns the process ID (e.g., 69420)
print(pid)

Getting a process name by using its ID

from pytaskmgr.process import Process
pid = 69420
proc = Process(pid=pid)
# Get the process ID
image_name = proc.get_image_name()
# Returns the process name (e.g., "example.exe")
print(image_name)

System Related

Getting the amount of RAM

from pytaskmgr.system import System
sys = System()
ram = sys.get_ram()
# Returns the amount of ram in MB (e.g., 8192MB)
print(ram)
# To convert to GB
print(ram.to_gb())

Getting the CPU uptime

from pytaskmgr.system import System
sys = System()
cpu = sys.get_cpu()
uptime = cpu.get_uptime()
# Returns the CPU uptime
print(uptime)

speaking of CPU... Getting the CPU Cores

from pytaskmgr.system import System
sys = System()
cpu = sys.get_cpu()
cores = cpu.get_cores()
# Returns the amount of cores (e.g., 4)
print(cores)

Getting CPU clock speed

from pytaskmgr.system import System
sys = System()
cpu = sys.get_cpu()
clock_speed = cpu.get_clock_speed()
# Returns the CPU clock speed in MHz (e.g., 3.65 MHz)
print(clock_speed)

Class Explanation

The Process() class allows you to interact with a system process by either its image name or PID (Process ID). Constructor Parameters:

  • image_name (str): The name of the process executable (e.g., "example.exe").
  • pid (int): The Process ID (e.g., 69420).

The constructor attempts to resolve the process using the following logic:

  1. If image_name is valid, it will use that.
  2. If image_name is invalid, it will fallback to using pid.
  3. If both are invalid, the library will raise an error.

This provides flexibility in managing processes even if you don't know the exact PID of a process.

The System() class contains information about your device, what more could you ask for?

Exceptions

ProcessNotFound: Occurs when the process couldn't be found.

AccessDenied: Occurs when the user doesn't have permission (by the system) to do harmful things (terminating, restarting the process)

ProcessCreationFailed: Occurs when the user tries to create a process, when either its executable is missing or received invalid parameters.

ProcessRestartFailed: Occurs when the process failed to restart.

Created by a programmer that sucks at programming, which is PolishBoiYT!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytaskmgr-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyTaskMGR-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file pytaskmgr-0.1.1.tar.gz.

File metadata

  • Download URL: pytaskmgr-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for pytaskmgr-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9a495992ea7613bda17e41286c6c47ce6dd0d95a65d35deac1945aaed5a034e8
MD5 277802f52a3c5f1bc6db3e7ce5b209bb
BLAKE2b-256 c6b40ed785c0dd35718e46ba80ec4fc429f2bf92500e437725a90f59b681d7dc

See more details on using hashes here.

File details

Details for the file PyTaskMGR-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: PyTaskMGR-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.6

File hashes

Hashes for PyTaskMGR-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d1a6233f1a0885931ea00dbcc6e42f9772bc40bfe6b993d403a11f9cb18ec0b
MD5 bbf60e0678a8b8f31b5ecd1f0be3f99e
BLAKE2b-256 cfdc77c9b8566ba5fc211faceef171859b443640bbd011b113a9142ef8ae622a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page