简体   繁体   English

Python selenium - 多处理 - 如何关闭已分配进程的浏览器?

[英]Python selenium - Multiprocessing - How to close browser for an allocated process?

I know you can use driver.quit() and driver.close() but how to close nicely when executed multiple processes?我知道您可以使用driver.quit()driver.close()但是在执行多个进程时如何很好地关闭?

IDEAS:想法:

  • Use process ID?使用进程 ID?

Using Selenium to end the WebDriver and Web Browser session graciously you should invoke the quit() method within the tearDown() {} .使用Selenium结束WebDriverWeb 浏览器session 您应该在tearDown() {}中调用quit()方法。 Invoking quit() deletes the current browsing session through sending quit command with {"flags":["eForceQuit"]} and finally sends the GET request on /shutdown endpoint.调用quit()通过发送带有{"flags":["eForceQuit"]}quit命令删除当前浏览的 session,最后在/shutdown端点发送GET请求。 Here is the relevant log:以下是相关日志:

1503397488598   webdriver::server   DEBUG   -> DELETE /session/8e457516-3335-4d3b-9140-53fb52aa8b74 
1503397488607   geckodriver::marionette TRACE   -> 37:[0,4,"quit",{"flags":["eForceQuit"]}]
1503397488821   webdriver::server   DEBUG   -> GET /shutdown

So on invoking quit() method the Web Browser session and the WebDriver instance gets killed completely.所以在调用quit()方法时 Web 浏览器 session 和 WebDriver 实例被完全杀死。

References参考

You can find a couple of relevant detailed discussions in:您可以在以下位置找到一些相关的详细讨论:

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

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