0

I have a simple long running python script which logs using print("text to log"). I want to run this as a background process but the output is only dumped into the specified log file when the process terminates. Is there a way to log in real time so that I can tail the logfile? I don't want to introduce unnecessary complexity in my python script; I'd rather allow the OS to handle the logging. Therefore I'm not keen in using a Logger class for example.

I've tried the alternatives below to no avail:

nohup python start.py > test.log 2>&1 </dev/null &
python start.py >> test.log 2>&1 &

Thx

chirinosky
  • 4,438
  • 1
  • 28
  • 39
user2177276
  • 3
  • 1
  • 2

1 Answers1

3

Try to run Python "unbuffered", i.e.

python -u start.py > test.log
uselpa
  • 18,732
  • 2
  • 34
  • 52