- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 selenium==3.141.0
编写一些自动化软件, python 3.6.7
, chromedriver 2.44
.
大部分逻辑都可以由单个浏览器实例执行,但对于某些部分,我必须启动 10-20 个实例才能获得不错的执行速度。
到了ThreadPoolExecutor
执行的部分,浏览器交互开始抛出此错误:
WARNING|05/Dec/2018 17:33:11|connectionpool|_put_conn|274|Connection pool is full, discarding connection: 127.0.0.1
WARNING|05/Dec/2018 17:33:11|connectionpool|urlopen|662|Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))': /session/119df5b95710793a0421c13ec3a83847/url
WARNING|05/Dec/2018 17:33:11|connectionpool|urlopen|662|Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fcee7ada048>: Failed to establish a new connection: [Errno 111] Connection refused',)': /session/119df5b95710793a0421c13ec3a83847/url
浏览器设置:
def init_chromedriver(cls):
try:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument(f"user-agent={Utils.get_random_browser_agent()}")
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(driver_paths['chrome'],
chrome_options=chrome_options,
service_args=['--verbose', f'--log-path={bundle_dir}/selenium/chromedriver.log'])
driver.implicitly_wait(10)
return driver
except Exception as e:
logger.error(e)
相关代码:
ProfileParser
实例化一个网络驱动程序并执行一些页面交互。我认为交互本身是不相关的,因为没有 ThreadPoolExecutor
一切都可以工作。 。然而,简而言之:
class ProfileParser(object):
def __init__(self, acc):
self.driver = Utils.init_chromedriver()
def __exit__(self, exc_type, exc_val, exc_tb):
Utils.shutdown_chromedriver(self.driver)
self.driver = None
collect_user_info(post_url)
self.driver.get(post_url)
profile_url = self.driver.find_element_by_xpath('xpath_here')]').get_attribute('href')
运行于 ThreadPoolExecutor
,此时出现上面的错误self.driver.find_element_by_xpath
或在 self.driver.get
这正在工作:
with ProfileParser(acc) as pparser:
pparser.collect_user_info(posts[0])
这些选项不起作用: ( connectionpool errors
)
futures = []
#one worker, one future
with ThreadPoolExecutor(max_workers=1) as executor:
with ProfileParser(acc) as pparser:
futures.append(executor.submit(pparser.collect_user_info, posts[0]))
#10 workers, multiple futures
with ThreadPoolExecutor(max_workers=10) as executor:
for p in posts:
with ProfileParser(acc) as pparser:
futures.append(executor.submit(pparser.collect_user_info, p))
更新:
我找到了一个临时解决方案(这不会使这个最初的问题无效) - 实例化 webdriver
ProfileParser
之外类(class)。不知道为什么它有效,但最初却不起作用。我想是某些语言细节的原因?感谢您的回答,但问题似乎不在于 ThreadPoolExecutor
max_workers
限制 - 正如您在其中一个选项中看到的那样,我尝试提交单个实例,但它仍然不起作用。
当前解决方法:
futures = []
with ThreadPoolExecutor(max_workers=10) as executor:
for p in posts:
driver = Utils.init_chromedriver()
futures.append({
'future': executor.submit(collect_user_info, driver, acc, p),
'driver': driver
})
for f in futures:
f['future'].done()
Utils.shutdown_chromedriver(f['driver'])
最佳答案
此错误消息...
WARNING|05/Dec/2018 17:33:11|connectionpool|_put_conn|274|Connection pool is full, discarding connection: 127.0.0.1
WARNING|05/Dec/2018 17:33:11|connectionpool|urlopen|662|Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))': /session/119df5b95710793a0421c13ec3a83847/url
WARNING|05/Dec/2018 17:33:11|connectionpool|urlopen|662|Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fcee7ada048>: Failed to establish a new connection: [Errno 111] Connection refused',)': /session/119df5b95710793a0421c13ec3a83847/url
...似乎是 urllib3
中的一个问题的连接池在执行 def _put_conn(self, conn)
时引发了这些警告 connectionpool.py中的方法。
def _put_conn(self, conn):
"""
Put a connection back into the pool.
:param conn:
Connection object for the current host and port as returned by
:meth:`._new_conn` or :meth:`._get_conn`.
If the pool is already full, the connection is closed and discarded
because we exceeded maxsize. If connections are discarded frequently,
then maxsize should be increased.
If the pool is closed, then the connection will be closed and discarded.
"""
try:
self.pool.put(conn, block=False)
return # Everything is dandy, done.
except AttributeError:
# self.pool is None.
pass
except queue.Full:
# This should never happen if self.block == True
log.warning(
"Connection pool is full, discarding connection: %s",
self.host)
# Connection never got put back into the pool, close it.
if conn:
conn.close()
<小时/>
ThreadPoolExecutor是 Executor使用线程池异步执行调用的子类。当与 Future 关联的可调用对象等待另一个 Future 的结果时,可能会发生死锁。
class concurrent.futures.ThreadPoolExecutor(max_workers=None, thread_name_prefix='', initializer=None, initargs=())
根据您的问题,当您尝试启动 10-20 个实例时,默认连接池大小 10 在您的情况下似乎不够,这是硬编码的adapters.py 。
此外,@EdLeafe 在讨论中Getting error: Connection pool is full, discarding connection提及:
It looks like within the requests code, None objects are normal. If
_get_conn()
gets None from the pool, it simply creates a new connection. It seems odd, though, that it should start with all those None objects, and that _put_conn() isn't smart enough to replace None with the connection.
但是合并Add pool size parameter to client constructor已经解决了这个问题。
将默认连接池大小增加为10,该大小之前已硬编码在adapters.py中现在可配置将解决您的问题。
<小时/>根据您的评论更新...提交单个实例,结果是相同的...。根据讨论中的 @meferguson84 Getting error: Connection pool is full, discarding connection :
I stepped into the code to the point where it mounts the adapter just to play with the pool size and see if it made a difference. What I found was that the queue is full of NoneType objects with the actual upload connection being the last item in the list. The list is 10 items long (which makes sense). What doesn't make sense is that the unfinished_tasks parameter for the pool is 11. How can this be when the queue itself is only 11 items? Also, is it normal for the queue to be full of NoneType objects with the connection we are using being the last item on the list?
这听起来像是您的用例中的一个可能原因。这可能听起来多余,但您仍然可以执行一些临时步骤,如下所示:
关于python - 连接池已满,通过Selenium和Python丢弃与ThreadPoolExecutor和多个 headless 浏览器的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53641068/
我正在尝试使用 firefox headless 在 headless (headless) redhat linux 构建机器上运行 selenium 测试。我创建驱动程序的方法如下所示: priv
关于这个主题有很多东西可以找到,但无法弄清楚。我需要滚动到(不太长)无限滚动页面的末尾。我有 2 个选项可以使用 chrome 非 headless (headless)但似乎不能 headless
我在远程服务器上运行 OpenFOAM,基本上设法通过 paraview 的 pvserver 可视化结果 as described here .然而,在连接后,客户端产生 Server DISPLA
我想在 headless 模式下截取 Android 设备的屏幕截图,也就是说我是这样创建的: echo no | /opt/android/android-sdk-linux/tools/andro
主要区别在于,基于GUI和非GUI(Headless)执行。 我正在寻找所有Headless浏览器之间的差异,但是很遗憾,我没有找到任何差异。我一个接一个地经历,这使我更加困惑。如果有人可以分享具有差
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我需要在没有 X 服务器的情况下执行 java 图像裁剪和调整大小。 我尝试了几种方法。下面的第一种方法有效,但输出了一个相当难看的调整大小的图像(可能使用最近邻算法来调整大小: static Buf
过去几天我一直在使用 Selenium、Tor 和 Firefox 作为多个任务的组合。我已经设法用 Python 编写了一个简单的脚本,它通过 Selenium 控制 Firefox,而 Firef
我正在使用 pygame 的操纵杆 api 在 headless (headless)系统上对我的项目使用操纵杆,但是 pygame 需要一个“屏幕”,所以我设置了一个虚拟视频系统来克服这个问题。它工
我想使用 headless firefox 在 macos 上捕获网页的图像。 这是我执行的命令:/Applications/Firefox.app/Contents/MacOS/firefox-bi
我正在使用带有 headless-chromium-php 的 google chrome headless (headless)浏览器 导航到某些网站,但它总是被验证码检测到 我尝试使用此 plug
是否有可能使用 Octave headless。 像这样的东西 octave result.txt 最佳答案 使用 octave --silent --eval 5+4 > result.txt 你会
我目前正在尝试在 headless (headless)模式下运行应用程序,我定义了后台回调: void callbackInBackground() { // Invoked from the s
我正在使用LibGDX headless backend运行jUnit测试。这在某些测试中效果很好,但是如果我尝试创建new Texture('myTexture.png');,则会收到NullPoi
我想在这个页面上使用 Selenium:https://www.avis.com/en/home 如果没有 headless (headless)模式,该代码一切正常: import requests
在Jasmine headless (headless)Webkit中运行测试时,我遇到了一个简单的TypeError: 'undefined' is not an object失败。但是没有提示在哪
我负责测试一个大量使用 AJAX 的企业 Web 应用程序。我需要构建一个系统,允许在没有人工干预的情况下连续运行测试。目前我最感兴趣的是负载测试,但我希望用于生成负载的相同脚本用于功能测试。 目前用
TL; DR:我可以配置一个容器来原生访问VGA,以覆盖主机视频输出吗? 我正在考虑处置低功耗的XenServer(以前为ESXi)白盒以设置docker最小安装(例如CoreOS,RancherOs
我正在尝试 headless (headless)运行我的测试,并将我的两个测试套件分片以并行运行它们。在我的本地计算机上,它们并行运行,但在这种 headless (headless)设置中,它们一
仍在尝试为大型大学项目(RCP 产品)建立 headless (headless)构建。 每个 Eclipse 用户都知道以下手动功能:“文件 --> 导入 --> 将现有项目导入工作区”以及“构建工
我是一名优秀的程序员,十分优秀!