Skip to content

Facing Message: 'ensuring close' #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
douglasdcm opened this issue Mar 15, 2025 · 1 comment
Open

Facing Message: 'ensuring close' #2163

douglasdcm opened this issue Mar 15, 2025 · 1 comment

Comments

@douglasdcm
Copy link

Hi, first of all thanks for maintaining this repository. I've integrated it with a library I've been working on and I faced the following error (see bellow)

I faced it when using undetected-chrome.ChromeOptions and headless=True in the the undetected-chrome.Chrome class. Not sure if it is an issue with the integration or this library itself.

To reproduce it

  1. Install guara (my library) with pip install guara
  2. run the test using pytest
# test_debug.py
import pytest
import undetected_chromedriver as uc
from guara.transaction import Application
from guara import it
from examples.web_ui.undetected_chromedriver import setup, actions


class TestUndetectedChromeDriver:
    def setup_method(self, method):
        self._app = Application(uc.Chrome(headless=True))
        self._app._driver = self._app.at(setup.OpenBrowserTransaction)._driver

    def teardown_method(self, method):
        self._app.at(setup.CloseBrowserTransaction)

    @pytest.mark.parametrize("query", ["Guara framework", "undetected-chromedriver"])
    def test_google_search(self, query):

        self._app.at(actions.SearchGoogle, query=query).asserts(
            it.Contains, "https://www.google.com/search"
        )

Other files

# setup.py
from guara.transaction import AbstractTransaction


class OpenBrowserTransaction(AbstractTransaction):
    """Open browser using undetected-chromedriver"""

    def __init__(self, driver=None):
        super().__init__(driver)

    def do(self):
        return self._driver  # Return the driver for Guará to manage


class CloseBrowserTransaction(AbstractTransaction):
    """Close the browser safely"""

    def __init__(self, driver):
        super().__init__(driver)

    def do(self):
        self._driver.quit()


# ============================== #
# actions.py
from guara.transaction import AbstractTransaction
from selenium.webdriver.common.by import By


class SearchGoogle(AbstractTransaction):
    """Perform a Google search"""

    def __init__(self, driver):
        super().__init__(driver)

    def do(self, query):
        self._driver.get("https://www.google.com")
        search_box = self._driver.find_element(By.NAME, "q")
        search_box.send_keys(query)
        search_box.submit()
        return self._driver.current_url

Error

examples/web_ui/undetected_chromedriver/test_undetected_chromedriver.py ..                                                             [100%]

============================================================== warnings summary ==============================================================
examples/web_ui/undetected_chromedriver/test_undetected_chromedriver.py::TestUndetectedChromeDriver::test_google_search[Guara framework]
examples/web_ui/undetected_chromedriver/test_undetected_chromedriver.py::TestUndetectedChromeDriver::test_google_search[undetected-chromedriver]
  /home/douglas/repo/tmp-projects/guara/venv/lib/python3.11/site-packages/undetected_chromedriver/patcher.py:254: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
    return LooseVersion(last_versions["channels"]["Stable"]["version"])

examples/web_ui/undetected_chromedriver/test_undetected_chromedriver.py::TestUndetectedChromeDriver::test_google_search[Guara framework]
examples/web_ui/undetected_chromedriver/test_undetected_chromedriver.py::TestUndetectedChromeDriver::test_google_search[undetected-chromedriver]
  /home/douglas/repo/tmp-projects/guara/venv/lib/python3.11/site-packages/undetected_chromedriver/__init__.py:363: DeprecationWarning: Use setlocale(), getencoding() and getlocale() instead
    language = locale.getdefaultlocale()[0].replace("_", "-")

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=============================================== 2 passed, 65 deselected, 4 warnings in 21.71s ================================================
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/logging/__init__.py", line 1113, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/usr/local/lib/python3.11/weakref.py", line 666, in _exitfunc
    f()
  File "/usr/local/lib/python3.11/weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
  File "/home/douglas/repo/tmp-projects/guara/venv/lib/python3.11/site-packages/undetected_chromedriver/__init__.py", line 848, in _ensure_close
    logger.info("ensuring close")
Message: 'ensuring close'
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/logging/__init__.py", line 1113, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/usr/local/lib/python3.11/weakref.py", line 666, in _exitfunc
    f()
  File "/usr/local/lib/python3.11/weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
  File "/home/douglas/repo/tmp-projects/guara/venv/lib/python3.11/site-packages/undetected_chromedriver/__init__.py", line 848, in _ensure_close
    logger.info("ensuring close")
Message: 'ensuring close'
Arguments: ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@douglasdcm and others