3 ms·
For what it's worth, I run into the same nuances frequently in Python. For example I often want to run some_script.py | tee log.txt But by default, Python
by oconnor663 5y ago
For what it's worth, I run into the same nuances frequently in Python. For example I often want to run
some_script.py | tee log.txt
But by default, Python will turn off line buffering when it detects it's not talking to a tty. So unless you know to call flush, or to add the right env var or interpreter flag, you're not going to see any early output from tee. This can be super confusing for newer programmers.
- DarylZero 5y agoIt's not Python, it's a generic Unix problem. This is why stdbuf exists. http://www.pixelbeat.org/programming/stdio_buffering/ http://www.pixelbeat.org/programming/stdio_buffering/
- css 5y ago> Python will turn off line buffering when it detects it's not talking to a tty Okay, I’ve been running into a bug in one of my Rust programs and I think this comment has the answer. My program uses a Command [0] to listen to stdin and stdout. Theoretically that Command should terminate when the parent process dies, but if the Command is a Python script that doesn’t include a `print()` with `flush=True`, it doesn’t die. I think you might have found my problem for me. [0]: https://docs.rs/tokio/1.15.0/tokio/process/struct.Command.html https://docs.rs/tokio/1.15.0/tokio/process/struct.Command.ht...