fix: 修复内存泄漏和僵尸进程问题

- 添加SIGCHLD信号处理器自动回收僵尸子进程
- 定期清理函数增加僵尸进程回收
- 增加batch_task_screenshots超时清理(30分钟)
- 增加pending_random_schedules超时清理(2小时)
- 修复playwright_automation.py的_force_cleanup使用SIGTERM+waitpid
- browser_installer.py浏览器检测后添加僵尸进程清理

内存占用从111MB降至53MB,僵尸进程从6个降至0个
This commit is contained in:
Yu Yon
2025-12-12 23:42:30 +08:00
parent 352c61fbd4
commit b905739515
3 changed files with 81 additions and 1 deletions

View File

@@ -6,6 +6,8 @@
"""
import os
import time
time.sleep(delay)
import sys
import shutil
import subprocess
@@ -72,6 +74,7 @@ class BrowserInstaller:
browser = p.chromium.launch(headless=True, timeout=5000)
browser.close()
self.log("✓ Chromium浏览器已安装且可用")
self._cleanup_zombie_processes()
return True
except Exception as e:
error_msg = str(e)
@@ -81,11 +84,30 @@ class BrowserInstaller:
if "Executable doesn't exist" in error_msg:
self.log("检测到浏览器文件缺失,需要重新安装")
self._cleanup_zombie_processes()
return False
except Exception as e:
self._cleanup_zombie_processes()
self.log(f"✗ 检查浏览器时出错: {str(e)}")
return False
def _cleanup_zombie_processes(self, delay=1):
"""清理僵尸子进程"""
try:
import os
import time
time.sleep(delay)
while True:
try:
pid, status = os.waitpid(-1, os.WNOHANG)
if pid == 0:
break
except ChildProcessError:
break
except Exception:
pass
def install_chromium(self):
"""安装Chromium浏览器"""
try: