Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - nohup.out don't show print statement

Tags:

python

nohup

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?

like image 698
Mario Avatar asked Sep 04 '14 20:09

Mario


People also ask

How do I ignore a print statement in Python?

If you don't want that one function to print, call blockPrint() before it, and enablePrint() when you want it to continue. If you want to disable all printing, start blocking at the top of the file.

Why nohup out is empty?

The short answer is to use nohup python -u args... to force python to print and flush buffer for each print() call. I believe this is due to Python's default behaviour to write to buffer first, but nohup doesn't trigger the buffer to be cleared.

What happens if I delete nohup out?

it will delete the contents of the file but not the file. It shouldn't. most probably nohup file is corrupted.

How do I use the nohup command without getting nohup out?

The nohup command only writes to nohup. out if the output is otherwise to the terminal. If you redirect the output of the command somewhere else - including /dev/null - that's where it goes instead.


1 Answers

You can use

nohup python -u python_script.py &
like image 69
Weiyu Cheng Avatar answered Sep 20 '22 14:09

Weiyu Cheng