我有一个成功运行的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] => )
答案 0 :(得分:1)
使用以下两个命令清除Linux缓存以解决此问题:
通过putty ssh shell输入。
/usr/sbin/tmpwatch 1 /tmp
和
/usr/sbin/tmpwatch 1 /var/tmp