From 5b22c56b7f31d930856a02fac29fe58ecd86a5a7 Mon Sep 17 00:00:00 2001 From: Sean Gomez <34379448+Sean-Gomez@users.noreply.github.com> Date: Wed, 30 Aug 2023 00:53:34 -0700 Subject: [PATCH 1/4] Update webdriver to close geckodrive log_output process on quit --- py/selenium/webdriver/firefox/webdriver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 8d30f5c8b417d..4c0905d09cd92 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -77,6 +77,7 @@ def quit(self) -> None: pass self.service.stop() + self.log_output.close() def set_context(self, context) -> None: self.execute("SET_CONTEXT", {"context": context}) From da98de235aedcff0d425143391d205d5bc085084 Mon Sep 17 00:00:00 2001 From: Sean-Gomez Date: Wed, 30 Aug 2023 01:57:14 -0700 Subject: [PATCH 2/4] Fixing syntax of log output close line in Python Firefox webdriver code --- py/selenium/webdriver/firefox/webdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 4c0905d09cd92..10560f1656ad3 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -76,8 +76,8 @@ def quit(self) -> None: # We don't care about the message because something probably has gone wrong pass + self.service.log_output.close() self.service.stop() - self.log_output.close() def set_context(self, context) -> None: self.execute("SET_CONTEXT", {"context": context}) From 75ed01ff9c97e157ef10451f252fb7025f90175b Mon Sep 17 00:00:00 2001 From: Sean-Gomez Date: Wed, 30 Aug 2023 16:02:53 -0700 Subject: [PATCH 3/4] add conditional to close log_output whether it be type int or if it's a file-like object --- py/selenium/webdriver/firefox/webdriver.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 10560f1656ad3..60a56c72bb2c1 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -21,7 +21,7 @@ import zipfile from contextlib import contextmanager from io import BytesIO - +from typing import TextIO from selenium.webdriver.common.driver_finder import DriverFinder from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver @@ -76,7 +76,10 @@ def quit(self) -> None: # We don't care about the message because something probably has gone wrong pass - self.service.log_output.close() + if isinstance(self.service.log_output,TextIO): + self.service.log_output.close() + elif isinstance(self.service.log_output,int): + os.close(self.service.log_output) self.service.stop() def set_context(self, context) -> None: From 0eab6cb32f21c66ce0a2b442a480205421f8e810 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Fri, 15 Sep 2023 21:36:30 -0500 Subject: [PATCH 4/4] [py] move closing logic to common driver --- py/selenium/webdriver/common/service.py | 15 +++++++-------- py/selenium/webdriver/firefox/webdriver.py | 6 +----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/py/selenium/webdriver/common/service.py b/py/selenium/webdriver/common/service.py index c6e24b0222912..6be3ecf3a2e8e 100644 --- a/py/selenium/webdriver/common/service.py +++ b/py/selenium/webdriver/common/service.py @@ -23,9 +23,9 @@ from abc import ABC from abc import abstractmethod from platform import system -from subprocess import DEVNULL from subprocess import PIPE from time import sleep +from typing import TextIO from urllib import request from urllib.error import URLError @@ -141,13 +141,12 @@ def send_remote_shutdown_command(self) -> None: def stop(self) -> None: """Stops the service.""" - if self.log_output != PIPE and not (self.log_output == DEVNULL): - try: - # Todo: Be explicit in what we are catching here. - if hasattr(self.log_output, "close"): - self.log_file.close() # type: ignore - except Exception: - pass + + if self.log_output != PIPE: + if isinstance(self.log_output, TextIO): + self.log_output.close() + elif isinstance(self.log_output, int): + os.close(self.log_output) if self.process is not None: try: diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 60a56c72bb2c1..8d30f5c8b417d 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -21,7 +21,7 @@ import zipfile from contextlib import contextmanager from io import BytesIO -from typing import TextIO + from selenium.webdriver.common.driver_finder import DriverFinder from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver @@ -76,10 +76,6 @@ def quit(self) -> None: # We don't care about the message because something probably has gone wrong pass - if isinstance(self.service.log_output,TextIO): - self.service.log_output.close() - elif isinstance(self.service.log_output,int): - os.close(self.service.log_output) self.service.stop() def set_context(self, context) -> None: