Skip to content

[BUG] Pyinstaller Windowed application has no stderr #1148

@mickmcc

Description

@mickmcc

Context:

  • Playwright Version: 1.18.2
  • Operating System: Windows 10
  • Python version: 3.9.2
  • Browser: Chromium (probably All)
  • Extra: Pyinstaller 4.8

Code Snippet

main.py:

from playwright.sync_api import sync_playwright

START_URL = 'https://playwright.dev/'

if __name__ == "__main__":

    exit_code = 1
    with sync_playwright() as p:
        browser = p.chromium.launch_persistent_context(
                                    headless=False,
                                    devtools=False,
                                    user_data_dir='',
                                    no_viewport=True)
        page = browser.new_page()
        try:
            page.wait_for_timeout(10 * 1000)
            page.goto(START_URL,
                      timeout=None)
            page.wait_for_timeout(10 * 1000)
            page.screenshot(path="chromium-screenshot.png")
            exit_code = 0
        except TimeoutError:
            print('Timeout occurred waiting for navigation to: ' + START_URL)
        browser.close()

    sys.exit(exit_code)

requirements.txt:

playwright==1.18.2
pyinstaller==4.8

pyinstaller commands (Batch) - Exception raised:

set PLAYWRIGHT_BROWSERS_PATH=0
playwright install chromium
pyinstaller -F --clean --windowed main.py

pyinstaller commands (Batch) - No Exception:

set PLAYWRIGHT_BROWSERS_PATH=0
playwright install chromium
pyinstaller -F --clean --console main.py

Describe the bug

Pyinstaller can be used to package applications in two forms:

  1. Console application. Console window created and output can be written to sys.stdout, sys.stderr
  2. Windowed application. No console created, only a GUI window. No sys.stdout or sys.stderr.

If a 'windowed' application is created, an exception occurs in Playwright as it tries to access stderr but this does not exist.
The use case is an GUI application (Tkinter) which uses Playwright to embed a browser session.

Exception stack trace:

    Traceback (most recent call last):
    File "main.py", line 20, in <module>
    File "playwright\sync_api\_context_manager.py", line 70, in __enter__
    File "playwright\sync_api\_context_manager.py", line 48, in greenlet_main
    File "asyncio\base_events.py", line 642, in run_until_complete
    File "playwright\_impl\_connection.py", line 172, in run_as_sync
    File "playwright\_impl\_connection.py", line 181, in run
    File "playwright\_impl\_transport.py", line 136, in connect
    File "playwright\_impl\_transport.py", line 129, in connect
    File "playwright\_impl\_transport.py", line 37, in _get_stderr_fileno
    AttributeError: 'NullWriter' object has no attribute 'closed'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions