【问题标题】:can one identify firefox browser instances leaking from selenium?可以识别从 selenium 泄漏的 firefox 浏览器实例吗?
【发布时间】:2022-12-15 20:23:36
【问题描述】:

我们运行了很多爬虫,我们似乎最终有很多额外的进程悬而未决。我们确保我们在运行结束时退出浏览器,但显然当抓取崩溃或中断时可能会发生某些事情。

当我运行“ps -auxwwwww”时,我看到(在 Ubuntu 20.04.2 LTS 系统上):

root      875464  875463  5 13:45 ?        00:11:15 /usr/bin/python3 foo1.py
root      909167  909166  2 16:30 ?        00:00:52 /usr/bin/python3 foo2.py
root      911702  911701  0 16:31 ?        00:00:13 /usr/bin/python3 foo3.py
root      915807  915805  1 16:35 ?        00:00:22 /usr/bin/python3 foo4.py
root      917485  917484  0 16:36 ?        00:00:13 /usr/bin/python3 foo5.py
root      919214  919213  8 16:37 ?        00:02:01 /usr/bin/python3 foo6.py
root      921380  921379 15 16:40 ?        00:03:06 /usr/bin/python3 foo7.py
root      926541  926540  0 16:48 ?        00:00:04 /usr/bin/python3 foo8.py

我看到这个,我想,我们有 8 次擦伤。好像还可以

但后来我也看到了这个:

root      766621       1 12 10:25 ?        00:50:29 /usr/lib/firefox/firefox --marionette --headless --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 -no-remote -profile /tmp/rust_mozprofileMLcj81
root      766774  766621 26 10:25 ?        01:45:31 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 233311 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 766621 true tab
root      766813  766621  1 10:25 ?        00:04:52 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 85 -prefMapSize 233311 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 766621 true tab
root      766926  766621  0 10:25 ?        00:00:01 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 7696 -prefMapSize 233311 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 766621 true tab

和这个:

root      916001  915970 21 16:35 ?        00:05:19 /usr/lib/firefox/firefox --marionette -headless start-maximized disable-infobars --disable-extensions --disable-application-cache --disable-gpu --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 -no-remote -profile /tmp/rust_mozprofileYc8Rmk
root      916120  916001  6 16:35 ?        00:01:38 /usr/lib/firefox/firefox -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab
root      916139  916001  1 16:35 ?        00:00:17 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 85 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab
root      916210  916001  0 16:35 ?        00:00:00 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 149 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab
root      916216  916001  0 16:35 ?        00:00:00 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 149 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab
root      916251  916001  0 16:36 ?        00:00:00 /usr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefsLen 1074 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab
root      916432  916001  0 16:36 ?        00:00:00 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -prefsLen 7899 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 916001 true tab      392663       1  1 Apr05 ?        2-04:16:25 /usr/lib/firefox/firefox --marionette -headless start-maximized disable-infobars --disable-extensions --disable-application-cache --disable-gpu --no-sandbox --disable-dev-shm-usage --ignore-certificate-errors user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36 -no-remote -profile /tmp/rust_mozprofileEHvISm
root      392826  392663  1 Apr05 ?        2-04:14:08 /usr/lib/firefox/firefox -contentproc -childID 2 -isForBrowser -prefsLen 85 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 392663 true tab
root      392877  392663  0 Apr05 ?        04:01:26 /usr/lib/firefox/firefox -contentproc -childID 3 -isForBrowser -prefsLen 85 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 392663 true tab
root      392881  392663  0 Apr05 ?        04:00:54 /usr/lib/firefox/firefox -contentproc -childID 4 -isForBrowser -prefsLen 85 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 392663 true tab
root      392927  392663  0 Apr05 ?        04:10:12 /usr/lib/firefox/firefox -contentproc -childID 5 -isForBrowser -prefsLen 1010 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 392663 true tab
root      393116  392663  0 Apr05 ?        00:29:37 /usr/lib/firefox/firefox -contentproc -childID 6 -isForBrowser -prefsLen 7899 -prefMapSize 233359 -jsInit 278680 -parentBuildID 20211028161635 -appdir /usr/lib/firefox/browser 392663 true tab

所以我看到了这些进程家族,其中这是一个父进程,然后是一堆以它为父进程的子进程。

但我没有看到 8 个进程家族。我看到了 20 套。

起初,我认为如果父进程的父进程是#1,那一定意味着那里有问题。但是只有 2 个进程族的根位于进程 1。

那么,到底是什么?

我有 8 个 scrape 正在运行,我应该有数百个进程在运行?做什么?

我可以重新启动机器,但这似乎很蹩脚。我想我可以让我们的脚本将它们的进程号写到某个数据存储中,然后查看这些进程是否存在。但是我好像应该可以看到,从运行的系统来看,如果这些进程是连接的,是吗?

有什么建议么?

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver firefox


    【解决方案1】:

    我们有同样的问题,但我现在对这件事了解更多:

    多进程 Firefox,也称为“Electrolysis”(通常简称为“e10s”),通过分离 Web 内容和 Firefox UI 进程来显着改善您的浏览体验。这意味着当网页消耗了计算机的大部分处理能力时,您的选项卡、按钮和菜单将不会锁定。

    你有很多的原因firefox -contentproc可能是您确实杀死了主要的 firefox 进程,但不幸的是,这并没有杀死子进程。

    那些在周围闲逛,这就是你看到它们的原因。

    我们需要实现自定义逻辑来“手动”终止子进程。

    有关这些过程的更多信息,请参阅https://wiki.mozilla.org/Electrolysis

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2016-02-15
      • 2017-07-29
      • 2011-03-08
      • 2016-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多