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.

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.0.tar.gz (3.9 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.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytaskmgr-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 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.0.tar.gz
Algorithm Hash digest
SHA256 3d42384240a0357d751c291f0671d5d289995524a6c5594265f306e2721d2a8d
MD5 3b0412309c3754e2fb2cc36f7c335362
BLAKE2b-256 ab9fb9b3f9b6ee214bea18fe6cb27cbe79304805c22f1d60c0dc052acb8bc709

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PyTaskMGR-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee387aa9753af5fd161af34f1400544fe303b6fc247df0be248d545f4be36323
MD5 99de98496cbedb0be055ca06e1eea6a8
BLAKE2b-256 b803f9812879902c092a895c6f68bbc131cef16373bca398eede8d4e73e1cd1f

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