0

I have a python program main.py which produces some outputs which I would like to write to a file. I want to execute the program non-blocking. Usually I would use python2.7 main.py > main.out & or nohup python2.7 main.py &> main.out &.

My problem is, that the program may run very long, and I want to have access to the output created so far before the program terminates. When I execute python2.7 main.py > main.out and I then stop the program with Ctrl-C the output file has the output created so far. However, with the nonblocking commands, the output-file remains empty during execution, and after I kill the program.

How do I do this?

1 Answer 1

1

You can try using the -u flag for python which will run the python process with unbuffered stdout/stderr

python2.7 -u main.py > main.out &
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.