Issue
I started running my python program on a server with:
nohup python program.py &
The program contains a loop which runs a function and prints its output each time:
for i in s:
print f(i)
I started the program yesterday, but my nohup.out
is still empty. I searched the internet and it seems python buffers the outputs. I don't want to stop and rerun my program. Is there any way to flush the outputs to nohup.out
now?
Solution
Not easily or reliably. I can describe something that might work, but I have never tested it in Python, and it has some assumptions.
Assuming that Python is using the libc stdio buffers, you might be able to attach to the running Python interpreter with gdb and use gdb to call fflush on stdout.
Be aware that this might crash your running program.
First find the PID of the python program.
Second, use GDB to attach to it: gdb --pid [PID from first step]
Third, in GDB type call fflush(stdout)
Then type detach
and then q
to get out of GDB.
No guarantees.
Answered By - Zan Lynx