Answers for "animate loading with itertools in python"

1

animate loading with itertools in python

import itertools
 import threading
 import time
 import sys

 done = False
 '|', '/', '-', '\\'
 def animate():
     for c in itertools.cycle(['|', '/', '-', '\\']):
         if done:
             break
         sys.stdout.write('\rAnything You Want Here' + c)
         sys.stdout.flush()
         time.sleep(0.1)
     sys.stdout.write('\rAnything Here To Run After 1 Second. Note 0.1 = 1 second     ')

 t = threading.Thread(target=animate)
 t.start()

 #long process here
 time.sleep(10)
 done = True
Posted by: Guest on September-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language