从内存中释放 Selenium chromedriver.exe [英] release Selenium chromedriver.exe from memory

查看:59
本文介绍了从内存中释放 Selenium chromedriver.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个 python 代码来运行 Selenium chromedriver.exe.在运行结束时,我有 browser.close() 来关闭实例.(browser = webdriver.Chrome()) 我相信它应该从内存中释放 chromedriver.exe (我在 Windows 7 上).但是,每次运行后,内存中都会保留一个 chromedriver.exe 实例.我希望有一种方法可以用 python 写一些东西来杀死 chromedriver.exe 进程.显然 browser.close() 没有完成这项工作.谢谢.

I set up a python code to run Selenium chromedriver.exe. At the end of the run I have browser.close() to close the instance. (browser = webdriver.Chrome()) I believe it should release chromedriver.exe from memory (I'm on Windows 7). However after each run there is one chromedriver.exe instance remain in the memory. I hope there is a way I can write something in python to kill the chromedriver.exe process. Obviously browser.close() doesn't do the work. Thanks.

推荐答案

根据 Selenium API,您确实应该调用 browser.quit() 因为此方法将关闭所有窗口并终止进程.您仍然应该使用 browser.quit().

per the Selenium API, you really should call browser.quit() as this method will close all windows and kills the process. You should still use browser.quit().

然而:在我的工作场所,我们在尝试在 Java 平台上执行 chromedriver 测试时发现了一个巨大的问题,即使在使用 浏览器之后,chromedriver.exe 实际上仍然存在.退出().为了解决这个问题,我们创建了一个类似于下面这个的批处理文件,它只是强制关闭进程.

However: At my workplace, we've noticed a huge problem when trying to execute chromedriver tests in the Java platform, where the chromedriver.exe actually still exists even after using browser.quit(). To counter this, we created a batch file similar to this one below, that just forces closed the processes.

kill_chromedriver.bat

kill_chromedriver.bat

@echo off
rem   just kills stray local chromedriver.exe instances.
rem   useful if you are trying to clean your project, and your ide is complaining.

taskkill /im chromedriver.exe /f

由于 chromedriver.exe 不是一个庞大的程序并且不会消耗太多内存,因此您不必每次都运行它,但仅在出现问题时才运行.例如在 Eclipse 中运行 Project->Clean 时.

Since chromedriver.exe is not a huge program and does not consume much memory, you shouldn't have to run this every time, but only when it presents a problem. For example when running Project->Clean in Eclipse.

这篇关于从内存中释放 Selenium chromedriver.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆