A cross-platform command and python script task launcher with process management.
Project description
TaskLauncher
🛠️ 跨平台进程与 Python 脚本启动、监控与管理工具
TaskLauncher 是一个轻量级的 Python 包,支持在多平台下安全、灵活地启动和管理任意系统命令或 Python 脚本。它支持任务运行时资源监控、进程终止、参数传递、异常保护等特性,专为自动化和系统集成场景设计。
主要功能
- 支持跨平台启动任意命令或 Python 脚本
- 自动识别主机操作系统信息
- 返回进程号、唯一任务标识(tag)及启动信息
- 实时获取进程资源占用、状态与运行时间
- 支持进程中止、强制杀死
- 支持参数化执行
- 失败时不会影响主进程或系统
- Python 脚本专属执行接口(自动格式化参数)
- 易于集成与扩展
安装
pip install tasklauncher
或从源码安装:
git clone https://github.com/yourgithub/TaskLauncher.git
cd TaskLauncher
pip install .
快速上手
启动任意命令
from tasklauncher.core import TaskLauncher
launcher = TaskLauncher()
result = launcher.run_command('ls' if launcher.system_info['system'] != 'Windows' else 'dir', shell=True)
print(result)
启动 Python 脚本(自动参数格式化)
info = launcher.run_python('example.py', 'arg1', 42)
print(info)
查询任务状态与资源
tag = info['tag']
status = launcher.task_status(tag)
print(status)
等待任务结束并获取输出
result = launcher.wait_task(tag)
print(result)
停止/强杀任务
launcher.stop_task(tag) # 优雅终止
launcher.stop_task(tag, force=True) # 强制杀死
API 参考
TaskLauncher 类
| 方法 | 说明 |
|---|---|
run_command(cmd, ...) |
启动任意命令,返回tag、pid等 |
run_python(pyfile, *args, python_executable, ...) |
启动Python脚本 |
stop_task(tag, force=False) |
停止(或强制终止)任务 |
task_status(tag) |
获取任务运行状态及资源情况 |
wait_task(tag, timeout=None) |
等待任务结束,获取输出 |
详见代码注释或文档。
测试
-
在
tests/目录中加入example.py:print("Hello, World!")
-
运行测试:
pip install pytest pytest tests/
如何贡献
- Fork 本项目并创建分支
- 提交 PR(合并请求)前请确保单元测试通过
- 欢迎修复bug、新增特性或优化文档
License
MIT License
联系
如有建议、需求或 bug,欢迎 issue 或 PR!
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 TaskLauncher-0.1.0.tar.gz.
File metadata
- Download URL: TaskLauncher-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e73b08122dd6aea19f76c61b9b64110424bca2b957cafe3ac6632e9eb8316d1b
|
|
| MD5 |
eaa2c545b47cff9269ae9eb7dbc231d5
|
|
| BLAKE2b-256 |
31db9dee3247b69346b1a5d945e277ef78b51b49faaa4273d985a39c495e35eb
|
File details
Details for the file TaskLauncher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: TaskLauncher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69d65c5f22ec5dd05c8f3c9367387efe295fe3be5f88c84bb3d41939e1f0c044
|
|
| MD5 |
5c56056dedc920abf53943738c6cc9be
|
|
| BLAKE2b-256 |
89568f41e59d226186fea4a0b581aa8ccb71830c2a69130da63b48b0f7cbfc64
|