Skip to content

Commit

Permalink
[py] close out logging on quit (#12637)
Browse files Browse the repository at this point in the history
* Update webdriver to close geckodrive log_output process on quit

* add conditional to close log_output whether it be type int or if it's a file-like object

* [py] move closing logic to common driver service

---------

Co-authored-by: titusfortner <[email protected]>
  • Loading branch information
Sean-Gomez and titusfortner authored Sep 16, 2023
1 parent 14e43b1 commit ed7ca49
Showing 1 changed file with 7 additions and 8 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

0 comments on commit ed7ca49

Please sign in to comment.