Skip to content

Commit

Permalink
[py] move closing logic to common driver
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 16, 2023
1 parent 75ed01f commit ec2a36d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
15 changes: 7 additions & 8 deletions py/selenium/webdriver/common/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 0 additions & 5 deletions py/selenium/webdriver/firefox/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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

Expand Down Expand Up @@ -76,10 +75,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:
Expand Down

0 comments on commit ec2a36d

Please sign in to comment.