Mario
Mario

Reputation: 2451

Python - nohup.out don't show print statement

Im new to python and web development, I have a basic issue I believe.
I'm running my server with pyramid, and I use nohup.out to write output to a file.

nohup ../bin/pserve development.ini  

When I do tail -f nohup.out
I can see all the output coming from the logging.info() calls in my code.
but I don't see all the output from the print() calls.

what is the reason for that, and how can I set it that I will see the print() in the nohup file?

Upvotes: 17

Views: 15348

Answers (3)

neel
neel

Reputation: 9061

You can use stdbuf -oL to flush the print statements. Command will look like

nohup stdbuf -oL python python_script.py > nohup.out &

Upvotes: 11

Weiyu Cheng
Weiyu Cheng

Reputation: 271

You can use

nohup python -u python_script.py &

Upvotes: 26

djmitche
djmitche

Reputation: 419

Printed output is buffered when not to a terminal. nohup replaces stdout with a non-terminal (a file, in fact).

In the absence of any code, all I can do is guess, but the most likely answer is that your output is buffered inside the python process, and when that buffer fills it will be flushed to nohup.out. To see if this is the case, try adding a lot more prints to fill up the buffer faster.

Upvotes: 4

Related Questions