Skip to content

Commit e4b87d4

Browse files
committed
[py]: Close FirefoxBinary log files when quitting Firefox driver instances. closes #11730
1 parent 6ef8cb8 commit e4b87d4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

py/selenium/webdriver/firefox/webdriver.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
import base64
18+
import logging
1819
import os
1920
import warnings
2021
import zipfile
@@ -32,6 +33,8 @@
3233
from .service import DEFAULT_EXECUTABLE_PATH
3334
from .service import Service
3435

36+
logger = logging.getLogger(__name__)
37+
3538
# Default for log_path variable. To be deleted when deprecations for arguments are removed.
3639
DEFAULT_LOG_PATH = None
3740
DEFAULT_SERVICE_LOG_PATH = "geckodriver.log"
@@ -212,8 +215,24 @@ def quit(self) -> None:
212215
rmtree(self.profile.path)
213216
if self.profile.tempfolder:
214217
rmtree(self.profile.tempfolder)
215-
except Exception as e:
216-
print(str(e))
218+
except Exception:
219+
logger.exception("Unable to remove profile specific paths.")
220+
221+
self._close_binary_file_handle()
222+
223+
def _close_binary_file_handle(self) -> None:
224+
"""Attempts to close the underlying file handles for `FirefoxBinary`
225+
instances if they are used and open.
226+
227+
To keep inline with other cleanup raising here is swallowed and
228+
will not cause a runtime error.
229+
"""
230+
try:
231+
if isinstance(self.binary, FirefoxBinary):
232+
if hasattr(self.binary._log_file, "close"):
233+
self.binary._log_file.close()
234+
except Exception:
235+
logger.exception("Unable to close open file handle for firefox binary log file.")
217236

218237
@property
219238
def firefox_profile(self):

0 commit comments

Comments
 (0)