Skip to content

Fix unwanted console window with pythonw on windows platform #729

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

Merged
merged 4 commits into from
May 31, 2021

Conversation

artyl
Copy link
Contributor

@artyl artyl commented May 31, 2021

I use playwright python in silent mode, my app runs in a background with no windows.
The Windows platform has a special way to run such applications - pythonw.exe
When I start the browser from my code, an unwanted black console window appears on the screen.
How to reproduce the problem:
Let's take simple script like this:

from playwright.sync_api import sync_playwright
with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("http://playwright.dev")
    page.screenshot(path="example.png")
    print(page.title())
    browser.close()

If we run this script like this:
python.exe sample.py
Everything will work fine and no windows will appear
If we run it like this
pythonw.exe sample.py
We will see a black console window associated with the call to playwright.cmd in the playwright-python library code.
At start pythonw.exe the console is not created, and sys.stdout is set to None.
Therefore, the playwright.cmd subprocess cannot join to the current sys.stdout (because it is None) and creates a new one

@artyl artyl changed the title Fix unwanted console window with pythonw on window Fix unwanted console window with pythonw on windows platform May 31, 2021
@artyl
Copy link
Contributor Author

artyl commented May 31, 2021

@mxschmitt, Is it okay that one required test is failed? Looks like this test was already broken in previous master commit: https://github.com/microsoft/playwright-python/runs/2675109661 (commit cf985f5)

@mxschmitt
Copy link
Member

Yup no worries, that's not related.

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

Successfully merging this pull request may close these issues.

2 participants