Why Isn’t My Python Script Output Updating in the Log File?

0
0
Asked By CuriousGiraffe27 On

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

Answered By HelpfulHedgehog34 On

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!

CuriousGiraffe27 -

Thank you so much. This helped.

Answered By OptimisticOtter22 On

You could also try running it with `nohup python3 my_script.py > myoutput.txt 2>&1`. Just a thought!

CuriousGiraffe27 -

Thanks for the idea. I've just tried. It doesn't make a difference.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.