Skip to content

Commit 1e07a85

Browse files
cgoldberglukeis
authored andcommitted
[py] fix shutdown and process termination (#3263)
1 parent acda925 commit 1e07a85

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ def send_remote_shutdown_command(self):
125125
url_request.urlopen("%s/shutdown" % self.service_url)
126126
except URLError:
127127
return
128-
count = 0
129-
while self.is_connectable():
130-
if count == 30:
128+
129+
for _ in 30:
130+
if self.is_connectable():
131131
break
132-
count += 1
133-
time.sleep(1)
132+
else:
133+
time.sleep(1)
134+
134135

135136
def stop(self):
136137
"""
@@ -160,14 +161,17 @@ def stop(self):
160161
except AttributeError:
161162
pass
162163
self.process.terminate()
163-
self.process.kill()
164164
self.process.wait()
165+
self.process.kill()
165166
self.process = None
166167
except OSError:
167-
# kill may not be available under windows environment
168168
pass
169169

170170
def __del__(self):
171-
# subprocess.Popen doesn't send signal on __del__;
172-
# we have to try to stop the launched process.
173-
self.stop()
171+
# `subprocess.Popen` doesn't send signal on `__del__`;
172+
# so we attemt to close the launched process when `__del__`
173+
# is triggered.
174+
try:
175+
self.stop()
176+
except Exception:
177+
pass

0 commit comments

Comments
 (0)