Skip to main content

nwtools

一个用于"负优化"系统性能的Python包。这个包主要用于演示、测试和教育目的,展示如何降低系统性能的各种方法。

⚠️ 警告:请谨慎使用!仅在测试环境或虚拟机中使用!

安装

pip install nwtools

功能特性

功能 说明
CPU负优化 创建大量计算密集型任务消耗CPU资源
内存负优化 分配大量内存但不释放
磁盘负优化 频繁读写磁盘,创建大量临时文件
网络负优化 发送大量网络请求,消耗带宽
进程负优化 创建大量子进程
UI干扰 干扰用户界面(需要pyautogui)
安全模式 所有操作都是可逆的,有安全限制

跨平台支持

  • ✅ Windows - 完全支持
  • ✅ Linux - 完全支持,可选dialog TUI
  • ✅ macOS - 基本支持

使用方法

命令行界面 (CLI)

# 显示帮助信息
nwtools --help

# 运行所有负优化功能(默认强度)
nwtools run

# 运行特定强度的负优化
nwtools run --intensity high

# 只运行CPU负优化
nwtools cpu --duration 30

# 运行内存负优化
nwtools memory --size 1024

# 运行磁盘负优化
nwtools disk --files 100

# 运行网络负优化
nwtools network --requests 50

# 运行进程负优化
nwtools process --count 20

# 停止所有负优化任务
nwtools stop

# 显示系统状态
nwtools status

Python API

from nwtools import NegativeOptimizer

# 创建优化器实例
optimizer = NegativeOptimizer()

# 运行CPU负优化
optimizer.optimize_cpu(duration=30, intensity="medium")

# 运行内存负优化
optimizer.optimize_memory(size_mb=512, duration=60)

# 运行磁盘负优化
optimizer.optimize_disk(num_files=50, file_size_kb=1024)

# 运行网络负优化
optimizer.optimize_network(num_requests=100, target_url="http://example.com")

# 运行进程负优化
optimizer.optimize_process(num_processes=10)

# 停止所有优化
optimizer.stop_all()

# 获取系统状态
status = optimizer.get_system_status()
print(f"CPU使用率: {status['cpu_percent']}%")
print(f"内存使用率: {status['memory_percent']}%")

TUI界面

TUI类型 命令 特点
稳定TUI(推荐) nwtools-stable-tui 纯Python实现,跨平台稳定,无需外部依赖
DIALOG TUI(仅Linux) nwtools-tui 使用dialog工具,支持鼠标点击
简单TUI nwtools-simple-tui 使用curses库(Linux/Mac)

💡 推荐:使用稳定TUI界面,因为它在所有平台上都能工作,不会崩溃,无需额外工具。

配置文件

可创建配置文件 ~/.nwtools/config.yaml 进行自定义设置:

defaults:
  intensity: medium
  duration: 60
  auto_cleanup: true
  
limits:
  max_cpu_percent: 80
  max_memory_mb: 2048
  max_disk_files: 100
  max_processes: 20
  
safety:
  require_confirmation: true
  max_total_duration: 300

依赖

  • Python >= 3.6
  • psutil >= 5.8.0
  • colorama >= 0.4.4
  • requests >= 2.25.0
  • pyyaml >= 5.4.0

可选依赖:

  • pyautogui >= 0.9.52 (用于UI干扰功能)
  • dialog (Linux系统,用于dialog TUI)

更新日志

v3.0.1 (2026-04-13)

  • 🔧 修复Windows兼容性问题
  • 🔧 修复psutil.disk_usage('/')在Windows上的错误
  • 🔧 修复进程创建在Windows上的参数问题
  • ✅ 添加跨平台TUI支持
  • ✅ 改进错误处理和依赖检查

v3.0.0 (2026-01-09)

  • 🎉 初始版本发布

免责声明

⚠️ 重要提示:

  • 本软件仅供测试、演示和教育目的使用
  • 作者不对使用本软件造成的任何损害负责
  • 请勿在生产环境或重要系统上使用
  • 使用风险自负!

许可证

MIT License

Metadata

Release files for nwtools 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nwtools 3.0.1
File Size Uploaded
nwtools-3.0.1.tar.gz 21.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nwtools 3.0.1
File Interpreter ABI Platform
nwtools-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.5 kB

Release files / nwtools-3.0.1.tar.gz

Download URL nwtools-3.0.1.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8dfb4ccb92d3b910ab5f1bd8c7b5acd6fa1c5fed878405ebe4d2a26787c26d13
BLAKE2b-256 checksum
How to use checksums
37adfec508b9c3db0e2b1924eecb9cc3e85536af55201600212220cd27840982
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / nwtools-3.0.1-py3-none-any.whl

Download URL nwtools-3.0.1-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76c128ea77323b2f9f85e0b3d1a0617b81daf99f0ee4a4bab452c74130729e67
BLAKE2b-256 checksum
How to use checksums
53c1c815cf2f85a83de7de2c54f7445d5f5f4c8c80c27886f98f63818d08bf09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page