SoFunction
Updated on 2024-12-10

Solve the problem of nohup executing python program log file write untimely problem

concern

Today I was executing a python program in the background with nohup and redirecting the standard and error output to a log file, but found it torturous that the log file was not updated until ages later. However the normal screen output was very timely.

Not sure if the program is running properly.

Example of running a script:

nohup python  >  2>&1 &

rationale

The output of python is buffered, resulting in not seeing the output right away.

prescription

Adding the -u argument to python makes python not enable caching.

nohup python -u  >  2>&1 &

And real-time tracking of file output to the screen:

tailf 

The above article to solve the problem of nohup execution python program log file is not written in time is all I have shared with you, I hope to be able to give you a reference, and I hope that you will support me more.