Skip to content

Commit ed7ca49

Browse files
[py] close out logging on quit (#12637)
* Update webdriver to close geckodrive log_output process on quit * add conditional to close log_output whether it be type int or if it's a file-like object * [py] move closing logic to common driver service --------- Co-authored-by: titusfortner <[email protected]>
1 parent 14e43b1 commit ed7ca49

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

py/selenium/webdriver/common/service.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
from abc import ABC
2424
from abc import abstractmethod
2525
from platform import system
26-
from subprocess import DEVNULL
2726
from subprocess import PIPE
2827
from time import sleep
28+
from typing import TextIO
2929
from urllib import request
3030
from urllib.error import URLError
3131

@@ -141,13 +141,12 @@ def send_remote_shutdown_command(self) -> None:
141141

142142
def stop(self) -> None:
143143
"""Stops the service."""
144-
if self.log_output != PIPE and not (self.log_output == DEVNULL):
145-
try:
146-
# Todo: Be explicit in what we are catching here.
147-
if hasattr(self.log_output, "close"):
148-
self.log_file.close() # type: ignore
149-
except Exception:
150-
pass
144+
145+
if self.log_output != PIPE:
146+
if isinstance(self.log_output, TextIO):
147+
self.log_output.close()
148+
elif isinstance(self.log_output, int):
149+
os.close(self.log_output)
151150

152151
if self.process is not None:
153152
try:

0 commit comments

Comments
 (0)