Skip to content

Commit eb0a321

Browse files
authored
don't leak a file descriptor to os.devnull by default (#13162)
* don't leak a file descriptor to os.devnull by default since this is passed along to subprocess directly we can use the subprocess constants still regression in #12103 * adjust condition for closing as well
1 parent 5138a9c commit eb0a321

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

py/selenium/webdriver/common/service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def __init__(
5656
) -> None:
5757
if isinstance(log_output, str):
5858
self.log_output = open(log_output, "a+", encoding="utf-8")
59-
elif log_output is subprocess.STDOUT:
59+
elif log_output == subprocess.STDOUT:
6060
self.log_output = None
61-
elif log_output is None or log_output is subprocess.DEVNULL:
62-
self.log_output = open(os.devnull, "wb")
61+
elif log_output is None or log_output == subprocess.DEVNULL:
62+
self.log_output = subprocess.DEVNULL
6363
else:
6464
self.log_output = log_output
6565

@@ -135,7 +135,7 @@ def send_remote_shutdown_command(self) -> None:
135135
def stop(self) -> None:
136136
"""Stops the service."""
137137

138-
if self.log_output != PIPE:
138+
if self.log_output not in {PIPE, subprocess.DEVNULL}:
139139
if isinstance(self.log_output, IOBase):
140140
self.log_output.close()
141141
elif isinstance(self.log_output, int):

0 commit comments

Comments
 (0)