With that said, the OP could definitely have done a better job making it clear that this problem isn't specific to Rust
With that said, the OP could definitely have done a better job making it clear that this problem isn't specific to Rust
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.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.ht...
I'm used to a raw stream allowing a few specific operations:
- read/write/peek one byte - write a byte array, but you must explicitly specify length and offset
So seeing a call that simply takes an entire byte string and writes it gives me "buffered I/O vibes". It's hard to quantify, but with how ubiquitous that pattern is I'd be surprised if there are a lot of people who expect similar.