I’m working on a script, which will print a timer and was trying to reuse a function like this:
def timer(m,x):
for i in range(1,x):
sys.stdout.write('\r%s\b%d' % (m,i))
sys.stdout.flush()
sleep(1)
sys.stdout.write('\r \b')
Now, the part of the script, where I want a timer to be displayed is like this:
host_alive = "ping -c1 myServer"
cmdStat, cmdOut = commands.getstatusoutput(host_alive)
while True:
if cmdStat != 0:
(cmdStat,cmdOut) = commands.getstatusoutput(host_alive)
print "Still NOT ready!!"
else:
break
How can I print a timer without specifying a range()? Is there any workaround?
Cheers!!
1 Answer