Repository navigation
Closed
Description
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
Labels
No labels
Activity
mxschmitt commentedon Jul 22, 2021
What would be your recommended approach to fix this?
kumaraditya303 commentedon Jul 22, 2021
To fix this issue we should clear all the pipes upon context manager exit and wait for the process to exit before interpreter shutdown. #819
pavelfeldman commentedon Aug 12, 2021
I am not sure this is worth fixing - my read on keyboard interrupt is that it can happen at any moment. Here you are handling it in run_until_complete, so there are good chances you catch it, but it leaves two questions:
I think your fix only raises more questions.
kumaraditya303 commentedon Aug 12, 2021
Since there is one main greenlet where the dispatcher switches, whenever the process is reading from driver the current call is in the
run_until_completehence that is the place which needs to be fixedWhat exception you are talking about and also from which it inherits? If it is
RuntimeErrorthen we should not do anything.Also because of the current bug the terminal hangs at least on windows when
CTRL-Cis pressed and leaves the current shell unusable.You should also try the solution and see if it fixes yourself on Windows 10.
kumaraditya303 commentedon Dec 3, 2021
Seems that it will not be fixed.