Skip to content

[BUG] Playwright should cleanly shutdown driver in sync_api  #818

Closed
@kumaraditya303

Description

@kumaraditya303

Platform : Windows 10 x64

Minimal reproducer:

from playwright.sync_api import Playwright, sync_playwright


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()

    page = context.new_page()

    page.goto("https://github.com/")
    page.wait_for_timeout(10e5)
    page.close()

    context.close()
    browser.close()


with sync_playwright() as playwright:
    run(playwright)

Wait for the browser to open and then CTRL+C to force exit, playwright does not closes the driver properly and tries to write to non-existing pipes.

Stacktrace:

Traceback (most recent call last):
  File "D:\playwright-python\main.py", line 19, in <module>
    run(playwright)
  File "D:\playwright-python\main.py", line 11, in run
    page.wait_for_timeout(10e5)
  File "D:\playwright-python\playwright\sync_api\_generated.py", line 7600, in wait_for_timeout
    self._sync(
  File "D:\playwright-python\playwright\_impl\_sync_base.py", line 109, in _sync
    self._dispatcher_fiber.switch()
  File "D:\playwright-python\playwright\sync_api\_context_manager.py", line 48, in greenlet_main
    loop.run_until_complete(self._connection.run_as_sync())
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 629, in run_until_complete
    self.run_forever()
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 316, in run_forever
    super().run_forever()
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 596, in run_forever
    self._run_once()
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\base_events.py", line 1854, in _run_once
    event_list = self._selector.select(timeout)
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 434, in select
    self._poll(timeout)
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\windows_events.py", line 783, in _poll
    status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
KeyboardInterrupt
Task was destroyed but it is pending!
task: <Task pending name='Task-7' coro=<Page.wait_for_timeout() done, defined at D:\playwright-python\playwright\_impl\_page.py:721> wait_for=<Task pending name='Task-8' coro=<sleep() running at c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\tasks.py:654> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002308DC80190>()]> cb=[<TaskWakeupMethWrapper object at 0x000002308DC801C0>()]> cb=[SyncBase._sync.<locals>.callback() at D:\playwright-python\playwright\_impl\_sync_base.py:104]>
Task was destroyed but it is pending!
task: <Task pending name='Task-8' coro=<sleep() running at c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\tasks.py:654> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000002308DC80190>()]> cb=[<TaskWakeupMethWrapper object at 0x000002308DC801C0>()]>
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x000002308D3353A0>
Traceback (most recent call last):
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\base_subprocess.py", line 125, in __del__
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\base_subprocess.py", line 70, in __repr__
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\proactor_events.py", line 79, in __repr__
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002308D336C10>
Traceback (most recent call last):
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\proactor_events.py", line 115, in __del__
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\proactor_events.py", line 79, in __repr__
  File "c:\users\kumar aditya\appdata\local\programs\python\python39\lib\asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe
ERROR: The process with PID 15060 (child process of PID 4464) could not be terminated.
Reason: The operation attempted is not supported.

ERROR: The process with PID 4464 (child process of PID 13744) could not be terminated.
Reason: There is no running instance of the task.

The process tried to write to a nonexistent pipe.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions