d-b
d-b

Reputation: 971

Force flush Python-part of Bash-script?

I have a simple Bash-script that spend more than 99 % of its time on executing a Python application (the script is just a wrapper that feeds this Python script files in a for-loop and renames the output files). I have the same problem as described here and have looked at the answers but don't understand how to use them in my context.

I think I need to apply the principles in the answers to that question inside my script, on the line that executes the Python script, but how?

My script as pseudo-code:

for file in "$directory"; do
    pythonscript "$file" >> "log.txt"; then
done

I want to flush the pythonscript-line every minute, every line of output it produces or similar, it doesn't matter that much (typically execution takes several hours, I just want to be able to track the output "reasonable" frequently).

Upvotes: 0

Views: 87

Answers (1)

Diego Torres Milano
Diego Torres Milano

Reputation: 69388

You can use PYTHONUNBUFFERED env var

export PYTHONUNBUFFERED=true
for file in "$directory"; do
    pythonscript "$file" >> "log.txt"; then
done

Upvotes: 1

Related Questions