I'm trying to print debug information inside a generator working with big list of data. But, I can see the result only when the generator finishes.
I am using python 3 and my code is as follows:
def generator():
    while 1:
        print ('.', end='')
        time.sleep(1)
        yield 1
for a in generator():
    print ('|', end='')
Result:
^C.|.|.|.|.|
Equivalent PHP7 code works as expected:
function generator()
{
    while (1) {
        echo '.';
        sleep(1);
        yield 1;
    }
}
foreach (generator() as $item) {
    echo '|';
}
Result:
.|.|.|.|.|^C
How to print debug information in realtime for each iteration of the generator's cycle?
 
    