playwright-python: [Question]: I run playwright failed.My program block at sync_playwright()

Your question

Hi, I’m trying to run an example as follows.


from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    for browser_type in [p.chromium, p.firefox, p.webkit]:
        browser = browser_type.launch()
        page = browser.new_page()
        page.goto('http://whatsmyuseragent.org/')
        page.screenshot(path=f'example-{browser_type.name}.png')
        browser.close()

the program blocked at ‘with sync_playwright() as playwright:’.

and when I stop the program, the ternimal print the information as follows:

C:\Users\H458951\AppData\Local\Programs\Python\Python311\python.exe C:\code\playwright-test\test.py 
Traceback (most recent call last):
  File "C:\code\playwright-test\test.py", line 3, in <module>
    with sync_playwright() as p:
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\site-packages\playwright\sync_api\_context_manager.py", line 88, in __enter__
    dispatcher_fiber.switch()
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\site-packages\playwright\sync_api\_context_manager.py", line 67, in greenlet_main
    self._loop.run_until_complete(self._connection.run_as_sync())
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 640, in run_until_complete
    self.run_forever()
^C  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 321, in run_forever
    super().run_forever()
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 607, in run_forever
    self._run_once()
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 1884, in _run_once
    event_list = self._selector.select(timeout)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 444, in select
    self._poll(timeout)
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_events.py", line 817, in _poll
    status = _overlapped.GetQueuedCompletionStatus(self._iocp, ms)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
Task was destroyed but it is pending!
task: <Task pending name='Task-3' coro=<Connection.run.<locals>.init() running at C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\site-packages\playwright\_impl\_connection.py:245> wait_for=<Future pending cb=[Task.task_wakeup()]> cb=[ProtocolCallback.__init__.<locals>.cb() at C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\site-packages\playwright\_impl\_connection.py:168]>
Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x0000000003024D60>
Traceback (most recent call last):
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 126, in __del__
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_subprocess.py", line 104, in close
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 109, in close
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 761, in call_soon
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 519, in _check_closed
RuntimeError: Event loop is closed
The process tried to write to a nonexistent pipe.
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0000000003026480>
Traceback (most recent call last):
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 116, in __del__
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 80, in __repr__
  File "C:\Users\H458951\AppData\Local\Programs\Python\Python311\Lib\asyncio\windows_utils.py", line 102, in fileno
ValueError: I/O operation on closed pipe

Process finished with exit code -1073741510 (0xC000013A: interrupted by Ctrl+C)

Playwright Version: 1.30 Operating System: Windows 10 Python: 3.11/3.9/3.10 Browser: All

What’s wrong with my computer? Thanks.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

Could you try to run the basic script and set the DEBUGP=1 environment variable? This should give some more debug information.