## python实现windows内存看门狗程序(带GUI界面)
### 1、程序核心
```
看门狗程序核心:
1、运行特定程序任务进程
2、监控任务管理器上的内存使用率
3、如果超过阈值则关闭该特定程序进程
4、重新开启该特定程序
5、重复过程2持续监控
```
### 2、程序流程
```
1、先编写UI界面,并转成py文件
2、实现具体的功能:获取当前内存,设置内存阈值,设置运行时间、获取目标程序路径、名称、开启监控、监控日志
3、使用nuitka打包成exe文件
```
### 3、核心代码
```python
def run(self):
'''
监控程序
'''
while 1:
self.qmut.lock()
if not self.window.is_run:
break
self.qmut.unlock()
time.sleep(5)
self._signal_monitor.emit(json.dumps({'get_memory': 'get_memory'})) # 发送信号给槽函数
time.sleep(5)
msg = '正在监控【{}】,当前内存:{},内存阈值:{}'.format(self.window.file_name_edit_value,
self.window.current_memory_edit_value,
self.window.memory_threshold_edit_value
)
self._signal_monitor.emit(json.dumps({'log': msg})) # 发送信号给槽函数
try:
if self.window.current_memory_edit_value > self.window.memory_threshold_edit_value:
msg = '内存{}%超过{}%,关闭程序'.format(self.window.current_memory_edit_value,
self.window.memory_threshold_edit_value
)
self._signal_monitor.emit(json.dumps({'log': msg})) # 发送信号给槽函数
while self.is_process_running(self.window.file_name_edit_value):
os.popen('taskkill /f /im {}'.format(self.window.file_name_edit_value)) # 关闭程序
time.sleep(2)
time.sleep(5)
while 1:
if self.is_process_running(self.window.file_name_edit_value):
break
msg = '开始重启【{}】'.format(self.window.file_name_edit_value)
self._signal_monitor.emit(json.dumps({'log': msg})) # 发送信号给槽函数
# 开启进程启动程序
p_array_main = Process(target=run,
name='monitor_run',
args=(self.window.file_path_edit_value, self.window.file_name_edit_value)
)
p_array_main.daemon = False # 设为【非守护进程】daemon=True 随主进程的结束而结束
p_array_main.start()
time.sleep(50)
if self.is_process_running(self.window.file_name_edit_value):
msg = '重启【{}】成功'.format(self.window.file_name_edit_value)
self._signal_monitor.emit(json.dumps({'log': msg})) # 发送信号给槽函数
break
time.sleep(120) # 休眠时间
except Exception as e:
self._signal_monitor.emit(json.dumps({'log': '出错了,{}'.format(e)})) # 发送信号给槽函数
```
### 4、打包
```
python -m nuitka --standalone --windows-disable-console --onefile --mingw64 --show-memory --show-progress --nofollow-import-to=pillow,PIL,,pyqt5 --enable-plugin=pyqt5 --output-dir=nuitka_out watchDogMain.py
```
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
看门狗程序核心: 1、运行特定程序任务进程 2、监控任务管理器上的内存使用率 3、如果超过阈值则关闭该特定程序进程 4、重新开启该特定程序 5、重复过程2持续监控 程序流程: 1、先编写UI界面,并转成py文件 2、实现具体的功能:获取当前内存,设置内存阈值,设置运行时间、获取目标程序路径、名称、开启监控、监控日志 3、使用nuitka打包成exe文件 python -m nuitka --standalone --windows-disable-console --onefile --mingw64 --show-memory --show-progress --nofollow-import-to=pillow,PIL,,pyqt5 --enable-plugin=pyqt5 --output-dir=nuitka_out watchDogMain.py
资源推荐
资源详情
资源评论
收起资源包目录
python实现的windows内存看门狗程序 (405个子文件)
__payload.bin 20.88MB
__constants.bin 5.06MB
module.zstandard.backend_cffi.c 3.71MB
module.psutil._pslinux.c 3.65MB
module.psutil.c 2.28MB
module.psutil._pswindows.c 1.67MB
module.urllib3.response.c 1.51MB
module.psutil._psbsd.c 1.42MB
module.psutil._pssunos.c 1.19MB
module.requests.utils.c 1.18MB
module.requests.models.c 1.11MB
module.psutil._common.c 1.1MB
module.urllib3.exceptions.c 1.03MB
module.psutil._psaix.c 1MB
module.psutil._psosx.c 885KB
module.urllib3.connectionpool.c 881KB
module.urllib3.connection.c 876KB
module.urllib3._collections.c 819KB
module.requests.sessions.c 808KB
module.urllib3.contrib.pyopenssl.c 791KB
module.idna.uts46data.c 729KB
module.__main__.c 727KB
module.requests.cookies.c 722KB
module.idna.core.c 653KB
module.requests.exceptions.c 583KB
module.urllib3.poolmanager.c 580KB
module.charset_normalizer.utils.c 578KB
module.charset_normalizer.cd.c 577KB
module.charset_normalizer.api.c 563KB
module.__parents_main__.c 552KB
module.charset_normalizer.models.c 540KB
module.psutil._compat.c 534KB
module.urllib3.util.url.c 529KB
module.requests.adapters.c 516KB
module.requests.auth.c 466KB
module.urllib3.util.retry.c 403KB
module.watchdog.c 369KB
module.urllib3.util.ssltransport.c 355KB
module.urllib3.util.ssl_.c 337KB
module.urllib3.contrib.socks.c 321KB
module.urllib3.fields.c 259KB
module.requests.c 234KB
module.psutil._psposix.c 228KB
module.requests.structures.c 224KB
module.urllib3.util.request.c 219KB
module.urllib3.util.timeout.c 196KB
module.urllib3.util.ssl_match_hostname.c 183KB
module.urllib3.util.connection.c 150KB
module.urllib3._request_methods.c 147KB
module.zstandard.c 140KB
module.urllib3.c 125KB
module.urllib3.util.wait.c 116KB
module.urllib3.filepost.c 108KB
module.idna.intranges.c 107KB
module.charset_normalizer.constant.c 97KB
module.requests.api.c 96KB
module.urllib3._base_connection.c 93KB
CompiledFunctionType.c 92KB
module.requests.status_codes.c 91KB
module.urllib3.util.response.c 86KB
__loader.c 85KB
module.requests.compat.c 72KB
module.certifi.core.c 71KB
module.charset_normalizer.legacy.c 68KB
module.requests.packages.c 67KB
module.urllib3.util.util.c 64KB
module.PyQt5.c 63KB
module.urllib3.util.c 60KB
module.requests._internal_utils.c 52KB
module.requests.hooks.c 51KB
module.multiprocessing-postLoad.c 50KB
module.charset_normalizer.c 48KB
module.idna.c 47KB
module.test.c 44KB
MainProgram.c 40KB
module.urllib3.util.proxy.c 33KB
module.multiprocessing-preLoad.c 33KB
module.PyQt5.QtCore-postLoad.c 30KB
OnefileBootstrap.c 30KB
module.certifi.c 29KB
module.urllib3.contrib.c 29KB
module.PyQt5-preLoad.c 26KB
module.requests.__version__.c 21KB
module.requests.certs.c 20KB
module.charset_normalizer.version.c 20KB
module.idna.idnadata.c 19KB
module.urllib3._version.c 19KB
module.idna.package_data.c 19KB
__helpers.c 14KB
__constants.c 5KB
__bytecode.const 4.41MB
module.idna.uts46data.const 97KB
module.zstandard.backend_cffi.const 94KB
module.psutil.const 50KB
module.psutil._pslinux.const 35KB
module.charset_normalizer.constant.const 24KB
module.urllib3.connectionpool.const 23KB
module.urllib3.response.const 21KB
module.psutil._pswindows.const 19KB
module.requests.utils.const 19KB
共 405 条
- 1
- 2
- 3
- 4
- 5
资源评论
东木月
- 粉丝: 4711
- 资源: 30
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功