Python Geckodriver 0.18.0随机无反应性。由几条壁虎河互相干扰引起的?

Python Geckodriver 0.18.0随机无反应性。由几条壁虎河互相干扰引起的?,python,selenium,firefox,geckodriver,xvfb,Python,Selenium,Firefox,Geckodriver,Xvfb,短版 我正在Ubuntu 14.04.5上运行Selenium 3.11.0+Geckodriver 0.18.0+Firefox 59.0.2。当尝试打开URL时,Selenium有时会抛出以下错误 [Errno 111] Connection refused https://www.example.com Geckodriver.log显示 1523165125053 geckodriver INFO geckodriver 0.18.0 1523165125060

短版

我正在Ubuntu 14.04.5上运行Selenium 3.11.0+Geckodriver 0.18.0+Firefox 59.0.2。当尝试打开URL时,Selenium有时会抛出以下错误

[Errno 111] Connection refused https://www.example.com
Geckodriver.log显示

1523165125053   geckodriver     INFO    geckodriver 0.18.0
1523165125060   geckodriver     INFO    Listening on 127.0.0.1:37893
1523165126313   geckodriver::marionette INFO    Starting browser /usr/bin/firefox with args ["-marionette"]
1523165127142   Marionette      INFO    Enabled via --marionette

(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(firefox:28158): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(firefox:28158): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_ref: assertion 'object->ref_count > 0' failed

(/usr/lib/firefox/firefox:28235): GLib-GObject-CRITICAL **: g_object_unref: assertion 'object->ref_count > 0' failed
1523165129816   Marionette      INFO    Listening on port 41316
1523165129876   Marionette      WARN    TLS certificate errors will be ignored for this session
ATTENTION: default value of option force_s3tc_enable overridden by environment.
JavaScript error: jar:file:///usr/lib/firefox/omni.ja!/components/PeerConnection.js, line 1816: TypeError: this._dompc._pc is undefined
[Child 28235, Chrome_ChildThread] WARNING: pipe error (16): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[Child 28235, Chrome_ChildThread] WARNING: pipe error (3): Connection reset by peer: file /build/firefox-4kFFck/firefox-59.0.2+build1/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
发生什么事了

长版本

我在cron中安排了一组夜间作业。它们是从如下所示的单个shell脚本开始的

if pgrep "Xvfb" > /dev/null
then
    echo "Xvfb already running"
else
        Xvfb :99 -screen 0 1024x768x24 2>&1 >/dev/null &
fi
export DISPLAY=:99
python dostuff.py
有几个贝壳和上面的一样。它们中的每一个都会启动一个Python2.7脚本(如上面示例中的dostuff.py),该脚本如下所示(唯一的区别是不同的URL集)

这在大多数情况下都可以正常工作,但有时脚本会变得无响应,我会收到一个连接被拒绝错误。这似乎总是发生在循环的中间。也就是说,URL[0]打开正常,但URL[1]可能会失败

在谷歌搜索geckodriver.log中的错误消息时,我发现了这个。由于我没有最大化任何窗口,我不认为我的问题与票证中描述的相同(尽管错误消息显示相似性)

我正在运行几个firefox实例(它们都使用相同的DISPLAY=:99)。这是否会导致不同的Firefox实例相互干扰

我还应该提到,当我使用Firefox44(不需要Geckodriver)时,这个设置工作得非常好。另一件可能很重要的事情是,据我所知,只有在使用Xvfb使用无头浏览器运行脚本时才会发生这种情况


从我的问题中可以看出,我对Xvfb、Geckodriver和Firefox有点不了解。如果有人知道发生了什么,我会很感激的

更新:更新到Geckodriver 0.20.1解决了这个问题-有点像


问题仍然存在(大约每打开100页就有一次)
driver.get(j)
偶尔会失败,但它会引发超时错误,可以捕获并处理该错误

我注意到我的壁虎河已经过时了。我会更新它并报告结果。潜在原因可能是某种特殊的w.r.t.硒+geckodriver+firefox+我的操作系统的组合,但我认为我自己的解决方案足以解决我自己的问题,所以我同意我自己的答案。我仍然很想知道是否还有其他人有类似的经历!谢谢
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
for j in list_of_urls:
    driver_get(j)
    # do stuff to j
driver.quit()