Tail -f doesn't seem to work in the shell when the file is populated via file.write ()

Greetings to all

I am trying to execute a daemonize python script that is currently running in the foreground. However, I still need to see its output, which it currently resets to standard output.

So, I use the following code snippet that generates a unique file name in / tmp and then assigns sys.stdout to this new file. All subsequent calls to "print" are then redirected to this log file.

import uuid
outfile = open('/tmp/outfile-' + str(uuid.uuid4()), 'w')
outfile.write("Log file for daemon script...\n")
sys.stdout=outfile

# Rest of script uses print statements to dump information into the /tmp file
.
.
.

The problem I am facing is that when I tail -fcreate a file created in / tmp, I do not see any output. However, as soon as I kill my daemon process, the output will be visible in the / tmp log file because python clears the file data.

tmp , , - .

, , unbeffered IO, .

!

, Warpcore

+3
1

-. , .

, , :

outfile = open(name, 'w', 0)
+4

Source: https://habr.com/ru/post/1784456/


All Articles