Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多处理,python-共享相同的webdriver指针_Python_Selenium_Webdriver_Multiprocessing - Fatal编程技术网

多处理,python-共享相同的webdriver指针

多处理,python-共享相同的webdriver指针,python,selenium,webdriver,multiprocessing,Python,Selenium,Webdriver,Multiprocessing,我找不到合适的答案,所以我发布了这个问题 理解问题的最快方法是目标: 有一个主流程和一个子流程(我要创建的那个)。主进程通过webdriver检查多个网站,但有时它被困在低硒级别,不想更改官方代码。所以我有时会手动检查监视器以检查进程是否被卡住,如果是这样,那么我会手动更改浏览器中的url,它会再次正常工作。我不想成为一个人类检查器。。因此,我希望使用共享同一webdriver的子流程来自动化任务,并通过webdriver.current\u url检查url,然后为我完成这项工作 下面是我在最

我找不到合适的答案,所以我发布了这个问题

理解问题的最快方法是目标:

有一个主流程和一个子流程(我要创建的那个)。主进程通过webdriver检查多个网站,但有时它被困在低硒级别,不想更改官方代码。所以我有时会手动检查监视器以检查进程是否被卡住,如果是这样,那么我会手动更改浏览器中的url,它会再次正常工作。我不想成为一个人类检查器。。因此,我希望使用共享同一webdriver的子流程来自动化任务,并通过
webdriver.current\u url
检查url,然后为我完成这项工作

下面是我在最小代表性示例表单中的尝试,其中子进程仅检测webdriver的url中的更改

def test_sub(driver):

    str_site0 = driver.current_url  # get the site0 url

    time.sleep(4)                   # give some time to the main-process to change to site1
    str_site1 = driver.current_url  # get the site1 url (changed by main-process)

    if str_site0 == str_site1:
        print('sub: no change detected')
    else:
        print('sub: change detected')
    #endif

#enddef sub



def test_main():
    """ main process changes from site0 (stackoverflow) to site1 (youtube)
        sub process detects this change of url of the webdriver object (same pointer) by using 
        ".current_url" method
    """

    # init driver
    pat_webdriver   = r"E:\WPy64-3680\python-3.6.8.amd64\Lib\site-packages\selenium\v83_chromedriver\chromedriver.exe"
    driver          = webdriver.Chrome(executable_path= pat_webdriver)
    time.sleep(2)


    # open initial site
    str_site0 = 'https://stackoverflow.com'
    driver.get(str_site0)
    time.sleep(2)


    # init sub and try to pass the webdriver object
    p = multiprocessing.Process(target=test_sub, args=(driver,)) # PROBLEM HERE! PYTHON UNCAPABLE
    p.daemon = False
    p.start()


    # change site
    time.sleep(0.5)                   # give some time sub query webdriver with site0
    str_site1 = 'https://youtube.com' # site 1 (this needs to be detected by sub)
    driver.get(str_site1)


    # wait the sub to detect the change in url. and kill process (non-daemon insufficient don't know why..)
    time.sleep(3)
    p.terminate()

#enddef test_main


# init the program (main-process)
test_main()
执行
$python test_multi thread.py
(它是测试脚本的名称…)时出现的相应错误如下:

不要试图将webdriver作为参数传递给process,否则将无法工作。重新设计您的应用程序,在流程工作者中实例化webriver。使用此代表性示例有何建议?考虑最小的例子,代码< >驱动器>获取(StruthSITE1)(接近脚本末尾)被堆叠。如果你能手动完成,那么就有可能进行编程。黄金问题是如何。不要试图将webdriver作为参数传递给process,它不会起作用。重新设计您的应用程序,在流程工作者中实例化webriver。使用此代表性示例有何建议?考虑最小的例子,代码< >驱动器>获取(StruthSITE1)(接近脚本末尾)被堆叠。如果你能手动完成,那么就有可能进行编程。黄金问题是如何。