Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds null checks for sys.stdout and sys.stderr before flushing them, which is necessary when packaging Python applications for distribution. In packaged GUI applications, these standard streams can be None, and attempting to flush them would cause an AttributeError.
Changes:
- Added defensive null checks before flushing standard output and error streams in two exit paths
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if sys.stdout: | ||
| sys.stdout.flush() | ||
| if sys.stderr: | ||
| sys.stderr.flush() |
There was a problem hiding this comment.
The condition if sys.stdout: may not be sufficient for packaged applications. In some environments, sys.stdout might be a non-None object that doesn't support the flush operation, or could be a redirected stream. Consider using a try-except block around the flush operations instead, which would be more robust and handle edge cases where the stream exists but flush() fails.
| if sys.stdout: | ||
| sys.stdout.flush() | ||
| if sys.stderr: | ||
| sys.stderr.flush() |
There was a problem hiding this comment.
The condition if sys.stdout: may not be sufficient for packaged applications. In some environments, sys.stdout might be a non-None object that doesn't support the flush operation, or could be a redirected stream. Consider using a try-except block around the flush operations instead, which would be more robust and handle edge cases where the stream exists but flush() fails.
开始打包