I'm using an older Xfce (Xubuntu) setup and running a Python script in a terminal like this: `python3 my_script.py &> my_script.log`. I'm monitoring the output with `tail -f my_script.log`, but I've noticed some weird buffering issues. The script's been running for about half an hour, and it should have generated over 300 lines of output, yet the log file is still 0 bytes until I ended the script manually. I've already attempted using `stdbuf -oL python3 my_script.py &> my_script.log`, but it hasn't changed anything. The output seems to only appear at the end instead of in real-time. What might be causing this, and is there a straightforward solution?
2 Answers
I had the same issue and found that using `python3 -u my_script.py` did the trick. The `-u` option forces the stdout and stderr streams to be unbuffered. So, definitely give that a shot!
You could also try running it with `nohup python3 my_script.py > myoutput.txt 2>&1`. Just a thought!
Thanks for the idea. I've just tried. It doesn't make a difference.
Thank you so much. This helped.