Why is my nohup.out empty?

I have a simple python script that just starts an infinite while loop and prints "running". When I run it with nohup in the background, I see the nohup.out file in the current directory, but nothing is ever written to it. I'm confused. I tried the following

nohup test.py 

writes in nohup.out, but obviously does not work in the background

 nohup test.py & 

works in the background, but does not write nohup.out

 nohup test.py 2>&1 & 

also works in the background, but does not write nohup.out

I bet I missed something simple. Any ideas?

Here is my python script for reference:

 import sys from time import sleep def main(): print "Starting...." while True: print "running..." sleep(5.00) if __name__ == "__main__": main() 
+4
source share
1 answer

Perhaps your stdout is not reset immediately because it is not connected to the terminal. Try using

 import sys sys.stdout.flush() 

to clear your exit.

+11
source

Source: https://habr.com/ru/post/1386735/


All Articles