Boiling down to the smallest problem here is a simple python script that I want to run using nohup on linux. I run it using the following (on linux):

 nohup python test.py &

The command seems to just not do anything, nothing is appended to nohup.out. If I run it without the '&' the output shows correctly on the terminal window. What am I missing?

 import time

 def test():
     print "Woke up!"

 if __name__ == "__main__":
  • Try sys.stdout.flush() and see if it works. – Michael Ma Mar 16 '17 at 1:33

Try running it with the command nohup python -u test.py &. This should make the output unbuffered.

You can make the script executable by adding a bang path as the first line with the -u option. Your will also need to set the executable bit with the command chmod +x test.py.

#!/usr/bin/python -u
import time

You can then run it as nohup test.py &.

| improve this answer | |

Block-based I/O buffering, I'd guess. What happens if you set the Python equivalent of setvbuf(3) line-based or unbuffered output on standard out?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.