[solved] How to see log in real time?

Hi people

I have a bash script with a line like this:

python example.py >> log &

But i can't see anything in the log file while python program is running only if the program ends seems to write the log file.

"$ cat log" for example don't show anything until the program ends.

Is there any way that can I read the log file although the program is running ?

Thanks a lot

Try

tail -f logfile

Thanks for response but this don't works.
I see the log file with "ls -l" that the file is 0KB until the program finish and then is full of all information.

It looks like python is buffering output so there is no external way to view the results until python flushes its output buffer. Normally this will happen when the buffer fills and when python closes the output file. If you have permission to change the python source file (example.py), consider adding flush() calls to appropriate spots in the code so tail will be able to see data written to the file after significant updates are written.

Thank you very much, this is the problem!
It can be solved adding a flush() method after the prints you want to flush:

import sys
sys.stdout.flush()

Adding a flush() class like this:

class flushfile(object):
    def __init__(self, f):
        self.f = f
    def write(self, x):
        self.f.write(x)
        self.f.flush()

import sys
sys.stdout = flushfile(sys.stdout)

Or more easily adding -u option when invoke python:

python -u example.py >> log &

then with tail command see any print in real time:

tail -f logfile

Thanks a lot
Solved