10

I call driver.quit() on test teardown, but the chromedriver process stays alive and doesn't shut down. So between executions sometimes Chrome doesn't open at all, and I need to manually shut down the processes. Someone familiar with this issue?

I'm using selenium 3.5

3
  • All the time or on sometimes? Also are you sure the quit is being called properly Commented Sep 28, 2017 at 8:01
  • Sometimes, and im sure Commented Sep 28, 2017 at 13:25
  • If I'm debugging and am regularly closing browser sessions or stopping execution, I will end up with a lot of chromedriver.exe processes alive and it's never caused me any problems. Post the teardown code. Put a log message in teardown and make sure that it's getting executed each time you think it is. What actual problem is this causing other than extra processes? Commented Sep 29, 2017 at 13:42

1 Answer 1

7

Change your code to below, to be double sure the process is not there after quit

import signal
import os
pid = driver.service.process.pid

driver.quit()
try:
    os.kill(int(pid), signal.SIGTERM)
    print("Killed chrome using process")
except ProcessLookupError as ex:
    pass
Sign up to request clarification or add additional context in comments.

6 Comments

import signal is missing here
additionally I would use signal.SIGKILL here since this is a fallback for when the driver does not quit
@Steinfeld, SIGKILL can be a bit brute, that is why you should use SIGTERM first
Does this still work for you? I am on Chrome 89 and it does not close the window (nor does it throw an exception)
@EvanHessler, A normal driver.quit() should work and this code is just for a handling unexpected scenarios
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.