您使用的是什么操作系统?如果您使用的是 POSIX OS,我认为它对应于下一个情况。
我创建了拉取请求,但它被拒绝了。
https://github.com/SeleniumHQ/selenium/pull/2244
但我认为显然是正确的吧。因此,我发布了一个问题。
https://github.com/SeleniumHQ/selenium/issues/2272
这个问题的根本原因是ghost驱动模式phatmojs的end方法不正确。最后不是不使用ghost驱动模式phantomjs的shutdown API。
对于您在 Linux 或 OSX 上的 npm 中安装的 phantomjs,
phantomjs 的 selenium 调用 Popen,lib/phantomjs.js 的 phantomjs 调用 spawn。此时,一个 selenium 是 parent,一个 phantomjs 是 child,lib/phantomjs.js 是 grandchild。
您在父级(硒)中调用 quit(),它会将 SIGTERM 发送给子级(phantomjs)。和一个孩子(phantomjs)在孩子的 SIGTERM 处理函数中向孙子(lib/phantomjs.js)发送 SIGTERM。
当父母在孩子向孙子发送 SIGTERM 之前向孩子发送 SIGKILL 时,孙子将成为僵尸。
此拉取请求 ttps://github.com/SeleniumHQ/selenium/pull/2244 使用幽灵驱动程序模式关闭 api 关闭。
def send_remote_shutdown_command(self):
super(Service, self).send_remote_shutdown_command() ## ADD A NEW LINE HERE
if self._cookie_temp_file:
os.close(self._cookie_temp_file_handle)
os.remove(self._cookie_temp_file)
其他解决方案,在“self.process.ternimate()”和“self.process.kill()”之间休眠。
ttps://github.com/SeleniumHQ/selenium/blob/051c8b110a1aec35247cd45fa4db85c6e522cdcb/py/selenium/webdriver/common/service.py#L151-L153
self.process.terminate()
time.sleep(1) ## ADD A NEW LINE HERE
self.process.kill()
self.process.wait()