Skip to content

Commit

Permalink
don't leak a file descriptor to os.devnull by default (#13162)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
asottile authored Nov 17, 2023
1 parent 5138a9c commit eb0a321
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __init__(
) -> None:
if isinstance(log_output, str):
self.log_output = open(log_output, "a+", encoding="utf-8")
elif log_output is subprocess.STDOUT:
elif log_output == subprocess.STDOUT:
self.log_output = None
elif log_output is None or log_output is subprocess.DEVNULL:
self.log_output = open(os.devnull, "wb")
elif log_output is None or log_output == subprocess.DEVNULL:
self.log_output = subprocess.DEVNULL
else:
self.log_output = log_output

Expand Down Expand Up @@ -135,7 +135,7 @@ def send_remote_shutdown_command(self) -> None:
def stop(self) -> None:
"""Stops the service."""

if self.log_output != PIPE:
if self.log_output not in {PIPE, subprocess.DEVNULL}:
if isinstance(self.log_output, IOBase):
self.log_output.close()
elif isinstance(self.log_output, int):
Expand Down

0 comments on commit eb0a321

Please sign in to comment.