python - 如果忽略 SIGCHLD,Firefox Webdriver 将无法工作

标签 python selenium-webdriver signals pyvirtualdisplay

我有以下代码片段可以正常工作:

from pyvirtualdisplay import Display
from selenium import webdriver

display = Display(visible=0, size=(800, 600))
display.start()
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print(browser.title)
browser.quit()
display.stop()

但是当我通过添加忽略 SIGCHLD 信号时

import signal
signal.signal(signal.SIGCHLD, signal.SIG_IGN)

到代码的开头,我收到以下错误:

selenium.common.exceptions.WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: b'Error: cannot open display: :1127\n'

忽略 SIGCHLD 与显示有何关系?以及如何解决它?

最佳答案

最后我通过处理 SIGCHLD 解决了这个问题,而不是忽略它:

def sigchld_nahdler(signum, frame):
    os.waitpid(0, 0)

signal.signal(signal.SIGCHLD, sigchld_handler)

关于python - 如果忽略 SIGCHLD,Firefox Webdriver 将无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21994097/

相关文章:

2.6 的 python 集理解

python - 如何使用 Selenium WebDriver 按名称定位文本输入?

c++ - pthreads - 强制线程运行

python - Butter Filter 和 FFT 得出的结果不会随时间变化

python - 使用 xlrd 将 xlsx 文件导入 Python

python - AWS SES 将自定义 header 添加到邮件中

Python错误: No handlers could be found for logger “xhtml2pdf”

java - Selenium 网格: How to retrieve node information from HUB programatically?

java - 无法使用 Robot 在 Selenium WebDriver 中拖放

linux - SIGHUP 重新加载配置