Skip to content

Commit

Permalink
redirect_output_to: flush(), fsync(), and close before resett…
Browse files Browse the repository at this point in the history
…ing stdout and stderr
  • Loading branch information
Thomas Fish committed Oct 16, 2024
1 parent e613e2b commit 7ff98c7
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/sim_recon/files/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,16 @@ def redirect_output_to(file_path: str | PathLike[str]) -> Generator[None, None,
except Exception:
logger.error("Failed to write output to log at %s", file_path, exc_info=True)
finally:
if f is not None:
f.flush()
if f_fd is not None:
os.fsync(f_fd)
f.close()
# Reset stdout and stderr file descriptors
os.dup2(saved_stdout_fd, stdout_fd)
os.dup2(saved_stderr_fd, stderr_fd)
sys.stdout = saved_stdout
sys.stderr = saved_sterr
if f_fd is not None:
os.fsync(f_fd)
if f is not None:
f.close()


def combine_text_files(
Expand Down

0 comments on commit 7ff98c7

Please sign in to comment.