Skip to content

[Bug]: #2854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Haohao268826 opened this issue May 16, 2025 · 3 comments
Closed

[Bug]: #2854

Haohao268826 opened this issue May 16, 2025 · 3 comments
Labels

Comments

@Haohao268826
Copy link

Version

latest

Steps to reproduce

1.clone this easy code example https://github.com/Haohao268826/PlayWrightRepo.git
2.On a Windows machine with Python (downloaded from python.org) installed and added to PATH.
3.pip install playwright
4.playwright install chromium
5.run python repoBug.py
6.Expected Behavior:
The script should launch a headless Chromium browser, navigate to example.com, print the title, and then close

Expected behavior

Print the log message: INFO:main:WindowsSelectorEventLoopPolicy has been set for minimal test.
Print the log message: INFO:main:Starting minimal Playwright test...
Successfully launch a headless Chromium browser instance managed by Playwright.
Print the log message: INFO:main:Browser launched.
Create a new browser page.
Print the log message: INFO:main:New page created.
Navigate the page to https://example.com.
Print a log message similar to: INFO:main:Navigated to example.com, page title: Example Domain
Close the browser cleanly.
Print the log message: INFO:main:Browser closed.
The script should then exit gracefully with a return code of 0, indicating success. No NotImplementedError or other critical errors should occur.

Actual behavior

errors.
Actual Behavior:
The script fails with a NotImplementedError originating from asyncio.base_events.py in the _make_subprocess_transport method. The WindowsSelectorEventLoopPolicy confirmation message is printed, indicating the policy was set.
Full Error Log:INFO:main:Starting minimal Playwright test...
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-2' coro=<Connection.run() done, defined at C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\site-packages\playwright_impl_connection.py:272> exception=NotImplementedError()>
Traceback (most recent call last):
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\site-packages\playwright_impl_connection.py", line 279, in run
await self._transport.connect()
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\site-packages\playwright_impl_transport.py", line 133, in connect
raise exc
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\site-packages\playwright_impl_transport.py", line 120, in connect
self._proc = await asyncio.create_subprocess_exec(
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\asyncio\subprocess.py", line 236, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 1676, in subprocess_exec
transport = await self._make_subprocess_transport(
File "C:\Users\Hao\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 498, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
CRITICAL:main:Top-level error occurred while running minimal test:
Traceback (most recent call last):

Additional context

This issue has been reproduced on two different Windows machines following the same setup steps (fresh Python from python.org, new virtual environment, fresh Playwright install).
The Python Scripts directory is confirmed to be in the system PATH.
The playwright install chromium command completes successfully without apparent errors.
Using Playwright's bundled Chromium (i.e., not providing executable_path to launch()).
Attempts to use different Python minor versions (e.g., previously tried Python 3.11 with the same error, now on Python [3.11]]) did not resolve the issue.
A complete uninstall (pip uninstall playwright, playwright uninstall) ayatannd reinstall (including pip cache purge) was performed before the latest test, with no change in outcome.
I suspect this might be a deeper compatibility issue between Playwright's subprocess management via asyncio and certain Windows environments or specific Python [Your Python Version] builds, despite the WindowsSelectorEventLoopPolicy being active.
Any insights or suggestions would be greatly appreciated. Thank you!

Environment

- Operating System: [windows11version23H2]and [windows10]
- CPU: [x64]
- Browser: [All, Chromium, Firefox, WebKit]
- Python Version: [3.12]and [3.9.13]
- Other info:
@ltsuda
Copy link

ltsuda commented May 16, 2025

Do you think this is the problem?

https://playwright.dev/python/docs/library#incompatible-with-selectoreventloop-of-asyncio-on-windows

@mxschmitt
Copy link
Member

mxschmitt commented May 17, 2025

Looks related to https://docs.python.org/3/library/asyncio-platforms.html#subprocess-support-on-windows yes.

Could you try changing the loop?

import asyncio

asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())

@Haohao268826
Copy link
Author

"Thanks for the @ltsuda @mxschmitt answer! I've tested it and the issue is resolved with ProactorEventLoop."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants