I wrote a python script to monitor the statuses of some network resources, an infinite pinger if you will. It pings the same 3 nodes forever until it receives a keyboard int
Here's a simpler way of reproducing your issue:
$ cat foo.py
from time import sleep
while True:
sleep(2)
print "hello"
$ python foo.py
hello
hello
(...)
$ python foo.py | tee log
(no output)
This happens because python
buffers stdout when it's not a terminal. The easiest way to unbuffer it is to use python -u
:
$ python -u foo.py | tee log
hello
hello
(...)
You can also set the shebang to #!/usr/bin/python -u
(this does not work with env
).