Add additional check to tell if it's safe to redirect stdout/err #270
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From #269, invoking a Corrfunc script as
python -u script.py &> out.txt
causes the script to hang. Something about the combination of redirection and unbuffered output was causing trouble. This change adds an additional check,sys.stdout is sys.__stdout__
, to see if Python'ssys.stdout
has been redirected elsewhere, like a Jupyter cell, in which case we want to follow that redirect. Otherwise, we don't touch anything.I don't exactly understand why unbuffered output causes a problem when buffered output did not, but I'm pretty confident that this new check more accurately reflects the scenarios in which we actually want redirection. This new check probably supersedes the
sys.stdout.isatty()
check, but to be conservative, we'll keep both.Minimal reproducer, note it is completely unrelated to Corrfunc:
This probably reflects my ignorance around pipes and fd's more than anything else!