从内存中释放Selenium chromedriver.exe [英] release Selenium chromedriver.exe from memory
问题描述
我设置了一个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.
推荐答案
,您确实应该调用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测试时注意到了一个巨大的问题,即使使用browser.quit()
,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屋!