Repository navigation
Leave stdout and stderr open when closing a FileWriter #94
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ def __init__(self, config: Config) -> None: | |
| super().__init__() | ||
| self._logger.info("initialize FileWriter to %s", config.location) | ||
|
|
||
| self._owns_file = config.location not in ("stderr", "stdout") | ||
| if config.location == "stderr": | ||
| self._file = sys.stderr | ||
| elif config.location == "stdout": | ||
|
|
@@ -28,4 +29,6 @@ def write(self, line: str) -> None: | |
| self._logger.error("failed to write line=%s", line) | ||
|
|
||
| def close(self) -> None: | ||
| self._file.close() | ||
| # stdout and stderr are not owned by this writer, so leave them open | ||
| if self._owns_file: | ||
| self._file.close() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should probably still flush the buffers
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, done in ee6ac89. close() now flushes stdout and stderr instead of leaving them untouched, and the test checks that flush is called. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be cleaner to have this updated in the appropriate branches below. That way it is colocated to keep in sync in the future if location options change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, moved it into each branch in ee6ac89 so the flag stays next to the location it belongs to.