From 0f03a04a1c4a0c2ec22e0e9b98e2eed79b4bfc71 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 16 Nov 2023 09:53:46 -0500 Subject: [PATCH 1/2] 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 --- py/selenium/webdriver/common/service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index d9ed63d8f299f6..21e53f2c38375a 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -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 From df054dbfcc7b4577a54ffd81dd013767ced6a1b5 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Thu, 16 Nov 2023 11:40:02 -0500 Subject: [PATCH 2/2] adjust condition for closing as well --- py/selenium/webdriver/common/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index 21e53f2c38375a..db8e486db3d3cb 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -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):