tags:

views:

148

answers:

3

I have a dead simple progress "bar" using something like the following:

import sys
from time import sleep

current = 0
limit = 50
while current <= limit:
    sys.stdout.write('\rSynced %s/%s orders' % (current, limit))
    current_order += 1
    sleep(1)

Works fine, except over ssh with Putty. Putty only updates every 3 minutes or if a line ends with \n. Is this a Putty setting, sshd_config, or can I code around it?

+3  A: 

Try doing sys.stdout.flush() after sys.stdout.write call.

sankoz
+1  A: 

You can use flush() to force an update.

sys.stdout.write('\r[%s%s]' % ('=' * completed, ' ' * (total-completed)))
sys.stdout.flush()
muhuk
A: 

Use sys.stderr.write instead, which is not buffered as sys.stdout is, and this way you separate progress indicator from the (presumably) useful process output.

ΤΖΩΤΖΙΟΥ