playwright-python
playwright-python copied to clipboard
[BUG] ValueError: I/O operation on closed pipe
Context:
- Playwright Version: Tested on Newest Pypi Version & Newest Github Release (Both result in this error)
- Operating System: Windows
- Python version: 3.10
- Browser: Firefox
Code Snippet
import asyncio
from playwright.async_api import async_playwright
async def test():
playwright = await async_playwright().start()
main_browser = await playwright.firefox.launch(headless=False)
browser = await main_browser.new_context()
page = await browser.new_page()
await page.goto("https://google.com")
await page.close()
await browser.close()
asyncio.run(test())
Describe the bug
When closing/quitting the Browser, it seems like the i/o pipe doesnt close properly.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002A3571AD900>
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 115, in __del__
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 79, in __repr__
info.append(f'fd={self._sock.fileno()}')
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_utils.py", line 102, in fileno
raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x000002A357183E20>
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\base_subprocess.py", line 125, in __del__
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\base_subprocess.py", line 70, in __repr__
info.append(f'stdin={stdin.pipe}')
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 79, in __repr__
info.append(f'fd={self._sock.fileno()}')
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_utils.py", line 102, in fileno
raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000002A3571AD900>
Traceback (most recent call last):
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 115, in __del__
_warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 79, in __repr__
info.append(f'fd={self._sock.fileno()}')
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\asyncio\windows_utils.py", line 102, in fileno
raise ValueError("I/O operation on closed pipe")
ValueError: I/O operation on closed pipe
I can repro.
Looks not like a regression to me, the Playwright instance gets manually created but not stopped so the transport stays open. You need to manually call await playwright.stop() if you are not using our context managers.
See here for context managers: https://playwright.dev/python/docs/library#usage
And here for playwright.stop(): https://playwright.dev/python/docs/library#interactive-mode-repl
After adding await playwright.stop() at the end after await browser.close() the script runs smoothly for me.