-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛 Bug]: Python - not shutting down Firefox/Geckodriver when service gets garbage collected #15399
Comments
@cgoldberg, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
Do you know if this is the case in other languages or just Python? |
I only use Python, but I'll try it in Ruby or Java when I get a chance. I suspect it's only Python and has something to do with the |
I’ll try to remember to take a deeper look when I have a chance and am not on my phone, but you might be right about it coming from service.py Good catch EDIT: Verfied in Python, driver hangs in Firefox but not Chrome. |
Here are the logs for both browsers: Firefox:
When I manually close the hanging browser, I get this:
Chrome:
Ideally we'd know when this started happening, but that isn't an easy answer to find. If it's just an issue in the python bindings, it shouldn't be a hard fix. Without knowing the cause, I can see how it could be Mozilla code, and I can see how it could be our code. EDIT: Here's code to check the logs: from selenium import webdriver
if __name__ == "__main__":
service = webdriver.firefox.service.Service(log_output="geckodriver.log")
driver = webdriver.Firefox(service=service)
service = webdriver.chrome.service.Service(log_output="chromedriver.log")
driver = webdriver.Chrome(service=service) |
I think this may be related to |
What happened?
(this issue is kind of long, but this behavior has been driving me crazy and I needed to document it so hopefully we can fix it)
Expected behavior:
When a Python script completes, Firefox and Geckodriver processes are terminated.
Actual behavior:
When a Python script completes, Firefox and Geckodriver processes are still running.
Why should they not be running?
Normally, you would launch Firefox by calling
driver = webdriver.Firefox()
. Once launched, you can calldriver.quit()
to stop Firefox and Geckodriver. This works fine.Alternately, you can launch Firefox by first creating a
service = webdriver.firefox.service.Service()
instance and using that when callingdriver = webdriver.Firefox(service=service)
. After that, you can stop the service withservice.stop()
. This should stop the Geckodriver process from running. This works fine.However, if you launch Firefox, then let your script end, the underlying
service
object gets destroyed during garbage collection and its__del__
method gets called. Insideservice.__del__()
is a call toservice.stop()
, which should stop the service and kill Geckodriver. For some reason, this isn't working and it leaves Firefox open and ageckodriver
process running.Firefox/Geckodriver behaves different than other browsers/drivers:
This is most noticeable by the difference in how Firefox behaves compared to other browsers.
For example, run the following code in a Python script (this won't be reproducible from an interactive interpreter, so make sure you create a script and call it from the command line):
After this script completes, you will notice Firefox is still visible and a
geckodriver
process is active:Now compare that to Chrome:
After this script completes, Chrome closes and and no
chromedriver
process is active:I think the Chrome behavior is correct and the Firefox is not.
This is most likely happening somewhere in
py/selenium/webdriver/common/service.py
... but I've been through the code and can't figure out why Firefox isn't properly terminated. It would be great to figure this out and have consistent behavior across all browsers/drivers.How can we reproduce the issue?
from selenium import webdriver driver = webdriver.Firefox()
Relevant log output
Operating System
Linux (Debian Stable)
Selenium version
Python Selenium 4.30
What are the browser(s) and version(s) where you see this issue?
Firefox 136.0 (64-bit)
What are the browser driver(s) and version(s) where you see this issue?
Geckodriver 0.36.0
Are you using Selenium Grid?
No
The text was updated successfully, but these errors were encountered: