我有一个成功运行的python脚本。.py 脚本将打开一个无头浏览器(pyvirtualdisplay & xvfb)并执行一项任务,然后关闭浏览器。脚本运行后,我遇到了 xvfb 进程保持打开状态的问题。运行多次后,它们往往会累积。我会定期通过 ssh shell 运行 killall 命令来杀死停滞的 xvfb 进程。这似乎没有引起任何问题。最近,我尝试通过设置执行以下命令的 cron 作业来自动化任务。
ps -eo pid,etime,comm | egrep '^ *[0-9]+ +([0-9]+-[^ ]*|[0-9]{2}:[0-9]{2}:[0-9]{2})' | grep Xvfb | awk '{print $1}' | xargs kill -9
这个命令只会杀死旧的 Xvfb 进程。我假设2小时大?由于我运行了此命令,因此无法运行 .py 脚本,并且收到以下错误:
<class 'selenium.common.exceptions.WebDriverException'>: Message: "The browser appears to have exited before we could connect. The output was: mkdir: cannot create directory `/.mozilla': Permission denied\nError: cannot open display: :9866\n" [83] =>
args = [84] => () [85] =>
message = [86] => '' [87] =>
msg = [88] => 'The browser appears to have exited before we cou...mission denied\nError: cannot open display: :9866\n' [89] =>
screen = [90] => None [91] =>
stacktrace = [92] => None [93] => [94] => [95] => [113] => )