microsoft / playwright-python

Python version of the Playwright testing and automation library.
https://playwright.dev/python/
Apache License 2.0
11.67k stars 886 forks source link

[BUG] Python scripts hangs on command "with sync_playwright() as p:" similar to #1773 #1810

Closed ChuckL3 closed 1 year ago

ChuckL3 commented 1 year ago

My issue appears very similar to #1773

Environment playwright Version: 1.31.1 Windows 11 Python 3.10.10 Browsers I have tried all of them but the code is never getting that far

Code Snippet from playwright.sync_api import sync_playwright DEBUGP=1

def main(): print ( "Pre sync_playwright()") with sync_playwright() as p: print ( "Post sync_playwright()") browser = p.chromium.launch() browser.close()

if name == "main": main()

results the output of this lines is the last thing displayed print ( "Pre sync_playwright()") and nothing else

I have tried reinstalling everything short of Python itself

When I ctrl-c the script here is what I get Pre sync_playwright() Traceback (most recent call last): File "C:\Users\chuck\OneDrive\git\Python\Development\Playwright_JoanMedia\Debug2.py", line 14, in main() File "C:\Users\chuck\OneDrive\git\Python\Development\Playwright_JoanMedia\Debug2.py", line 8, in main with sync_playwright() as p: File "c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright\sync_api_context_manager.py", line 91, in enter dispatcher_fiber.switch() File "c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright\sync_api_context_manager.py", line 70, in greenlet_main self._loop.run_until_complete(self._connection.run_as_sync()) File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete self.run_forever() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever super().run_forever() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever self._run_once() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1884, in _run_once event_list = self._selector.select(timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 444, in select self._poll(timeout) File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 817, in _poll status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyboardInterrupt ^CTask was destroyed but it is pending! task: <Task pending name='Task-3' coro=<Connection.run..init() running at c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright_impl_connection.py:245> wait_for= cb=[ProtocolCallback.init..cb() at c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright_impl_connection.py:168]> Exception ignored in: <function BaseSubprocessTransport.del at 0x000001EB4B994680> Traceback (most recent call last): File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 126, in del File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 104, in close File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 109, in close File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 761, in call_soon File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x000001EB4B995E40> Traceback (most recent call last): File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 116, in del File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in repr File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno ValueError: I/O operation on closed pipe (env) PS C:\Users\chuck\OneDrive\git\Python\Development>

I have disabled my VPN, Norton Antivirus and Auto-Protect

Add any other details about the problem here.

mxschmitt commented 1 year ago

Did you set the DEBUGP=1 environment variable?

$Env:DEBUGP=1 in PowerShell and set DEBUGP=1 in Batch. And then run your program again.

ChuckL3 commented 1 year ago

Yes I have set and verified the Environment Variable is set to DEBUGP=1

And get the same results after Ctrl-C on the apparently hung process

Pre sync_playwright() Traceback (most recent call last): File "C:\Users\chuck\OneDrive\git\Python\Development\Playwright_JoanMedia\Debug2.py", line 14, in main() File "C:\Users\chuck\OneDrive\git\Python\Development\Playwright_JoanMedia\Debug2.py", line 8, in main with sync_playwright() as p: File "c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright\sync_api_context_manager.py", line 91, in enter dispatcher_fiber.switch() File "c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright\sync_api_context_manager.py", line 70, in greenlet_main self._loop.run_until_complete(self._connection.run_as_sync()) File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete self.run_forever() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever super().run_forever() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever self._run_once() File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1884, in _run_once event_list = self._selector.select(timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 444, in select self._poll(timeout) File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 817, in _poll status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ KeyboardInterrupt ^CTask was destroyed but it is pending! task: <Task pending name='Task-3' coro=<Connection.run..init() running at c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright_impl_connection.py:245> wait_for= cb=[ProtocolCallback.init..cb() at c:\Users\chuck\OneDrive\git\Python\Development\env\Lib\site-packages\playwright_impl_connection.py:168]> Exception ignored in: <function BaseSubprocessTransport.del at 0x00000203360A4680> Traceback (most recent call last): File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 126, in del File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 104, in close File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 109, in close File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 761, in call_soon File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed RuntimeError: Event loop is closed Exception ignored in: <function _ProactorBasePipeTransport.del at 0x00000203360A5E40> Traceback (most recent call last): File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 116, in del File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in repr File "C:\Users\chuck\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno ValueError: I/O operation on closed pipe (env) PS C:\Users\chuck\OneDrive\git\Python\Development>

mxschmitt commented 1 year ago

Looks like this cannot be diagnosed easily over GitHub issues. If you don't mind, feel free to ping me on Discord and we can have a short debugging session.

mxschmitt commented 1 year ago

Closing as part of the triage process since we were not able to reproduce this. Feel free to re-file with more debugging information. Thanks for your understanding!