Skip to content

fix: handle pyinstaller app with no stderr (#1148) #1154

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
Feb 8, 2022

Conversation

mickmcc
Copy link
Contributor

@mickmcc mickmcc commented Feb 8, 2022

Proposed fix for issue #1148.

When playwright is running in an application which was packaged by pyinstaller, stderr can be of type NullWriter which has no attribute closed. Moved access to the attribute closed inside the following try clause to handle the AttributeError.
Re-run unit tests after the change an no additional failures seen.

return sys.stderr.fileno()
except (AttributeError, io.UnsupportedOperation):
# pyinstaller apps may not have stderr
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it pythonw specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right. I was focused only on pyinstaller but it is specific to pythonw.
I will update the comment. Would you prefer this scenario to be handled differently in the method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems alright, but we could also check above if it's a nullwriter which seems cleaner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the branch as pythonw and pyinstaller scenarios are different.

  • In case of pythonw, sys.stderr is None
  • In case of pyinstaller, sys.stderr is an instance of NullWriter class from the pyinstaller package.

Moved the check for these two situations to early in the try clause. Don't explicitly check for NullWriter class as this is from another package so added a generic check if sys.stderr has attribute closed.

@mxschmitt mxschmitt merged commit 3cb3bac into microsoft:main Feb 8, 2022
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