Search code examples
pythondebuggingexceptionstderrnohup

no error messages with nohup and python?


I run a python script on a linux server with nohup like that:

nohup python3 ./myscript.py > ./mylog.log &

It works and the script writes the log file but the problem is that python error messages / thrown exceptions don't seem to get written into the log file. How could I achieve this?

Has this something to do with stderr? (but it says: "nohup: redirecting stderr to stdout" when I start the script.)

It is a long running script and after a while sometimes the script stops working because of some problem and with missing error messages I have no clue why. The problems always happen after a few days so this is really a pain to debug.

edit: Could it have something to do with flush? Since my own prints use flush but maybe python errors don't so they don't show up in the file once the script aborts?


Solution

  • I have found the reason. It really was the buffering problem (see my edit above). :)

    nohup python3 -u ./myscript.py > ./mylog.log &
    

    With the python -u parameter it works. It disables buffering.

    Now I can go bug hunting...