When launching a Python process, in background, with
nohup python myscript.py > test.log 2>&1 < /dev/null &
the problem is
There are multiple ways of handling this.
import sys
def log(msg):
sys.stdout.write(msg)
sys.stdout.flush()
log("Hello World!")
Use mkfifo command to create your own logging device and write to it instead of stdout. Use a separate command to pipe from device to a file.
Write a log file directly and flush when you do. Same as number one, but avoids using stdout altogether. This is what I would do.
I would be suspicious of nohup. Terminal opens standard i/o streams and passes them to processes. If you run a process with nohup and then logout and close the terminal, I am not sure what happens to the standard streams. It might be that OS does some sort of garbage collect and closes them leaving your process without stdout. You should really consider writing your own logs.