简体   繁体   English

无法连接到 python 中的分离 selenium window

[英]Can`t attach to detached selenium window in python

Cant send commands to selenium webdriver in detached session because link http://localhost:port died.无法在分离的 session 中向 selenium webdriver 发送命令,因为链接 http://localhost:port 死了。

But if i put breakpoint 1 link stay alive但是如果我把断点 1 链接保持活动状态

import multiprocessing
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

def create_driver_pool(q):
    options = Options()
    driver = webdriver.Chrome(options=options)
    pass #breakpoint 1
    return driver.command_executor._url

windows_pool = multiprocessing.Pool(processes=1)
result = windows_pool.map(create_driver_pool, [1])
print(result)
pass # breakpoint 2 for testing link

why is this happening and what can i do about it?为什么会发生这种情况,我该怎么办?

After some research i finally found the reason for this behavor.经过一番研究,我终于找到了这种行为的原因。 Thanks https://bentyeh.github.io/blog/20190527_Python-multiprocessing.html and some googling about signals.感谢https://bentyeh.github.io/blog/20190527_Python-multiprocessing.html和一些关于信号的谷歌搜索。 This is not signals at all.这根本不是信号。 I found this code in selenium.common.service我在 selenium.common.service 中找到了这段代码

    def __del__(self):
        print("del detected")
        # `subprocess.Popen` doesn't send signal on `__del__`;
        # so we attempt to close the launched process when `__del__`
        # is triggered.
        try:
            self.stop()
        except Exception:
            pass

This is handler for garbage collector function, that killing subprocess via SIGTERM这是垃圾收集器 function 的处理程序,通过 SIGTERM 杀死子进程

                self.process.terminate()
                self.process.wait()
                self.process.kill()
                self.process = None

But if you in the debug mode with breakpoint, garbage collector wont collect this object, and del wont start.但是如果你在带断点的调试模式下,垃圾收集器不会收集这个 object, del不会启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM