A Python library for Windows to programmatically limit the CPU usage of running processes
Project description
cpulimiter 🚀
A Python library for Windows to limit the CPU usage of running processes.
Features ✨
- 🎯 Limit process CPU usage by a specified percentage.
- 🔍 Target processes by Process ID (PID), executable name, or window title.
- 🤝 Manage and control multiple limited processes simultaneously.
- 🛠️ Utility functions to discover running and active processes.
Installation 📦
pip install cpulimiter
(Note: This package is not yet published to PyPI.)
Quick Start 📖
The following example demonstrates how to limit chrome.exe to 5% of CPU usage (a 95% limit).
from cpulimiter import CpuLimiter
import time
# 1. Initialize the limiter
limiter = CpuLimiter()
# 2. Add the process directly by its name.
# The library will find the PID for "chrome.exe" for you.
limiter.add(process_name="chrome.exe", limit_percentage=95)
# 3. Start the limit
# You can also start it by name.
print("Limiting Chrome for 15 seconds...")
limiter.start(process_name="chrome.exe")
time.sleep(15)
# 4. Stop the limit
print("Stopping limit.")
limiter.stop(process_name="chrome.exe")
print("Process limit removed.")
API Reference
CpuLimiter Class
The primary class for managing process limits.
limiter.add(pid, process_name, window_title_contains, limit_percentage)
Adds a process to the limiter's management list.
pid(int): The Process ID.process_name(str): The executable name (e.g.,"chrome.exe").window_title_contains(str): A substring to match in a window title.limit_percentage(int): The percentage by which to limit the CPU (e.g.,95means the process can use up to 5% of a core).
limiter.start(pid, process_name, window_title_contains)
Starts the CPU limit on a specific, previously added process.
limiter.stop(pid, process_name, window_title_contains)
Stops the CPU limit on a specific process.
limiter.start_all()
Starts the CPU limit on all managed processes.
limiter.stop_all()
Stops the CPU limit on all managed processes.
Utility Functions
get_active_window_info()
Returns a dictionary containing the pid, name, and title of the foreground window.
get_active_app_pids()
Returns a dictionary of all processes with visible windows.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cpulimiter-1.0.0.tar.gz.
File metadata
- Download URL: cpulimiter-1.0.0.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0263422fa04cbaf6b96721830a5a9ab1fbe2ecdfb93da31cf2eeeb67422d07e0
|
|
| MD5 |
cbb3e2c54fad2add53a80c664fc7231d
|
|
| BLAKE2b-256 |
f8947fb538bd7c4d8dbad87c65c722da87a4d28172a9a9ee39a738978d7eafad
|
File details
Details for the file cpulimiter-1.0.0-py3-none-any.whl.
File metadata
- Download URL: cpulimiter-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d032b058128b3c69934846a54dee686ef2897006f78a0c2611a0bd0edfba993
|
|
| MD5 |
1e309f6502bd632380fd6324a98bde90
|
|
| BLAKE2b-256 |
dfaff38da7a38b497eda89e0e66f2195e2f07e7ecd490068a2d98f2f5e4a7903
|