animate loading with itertools in python

Solutions on MaxInterview for animate loading with itertools in python by the best coders in the world

showing results for - "animate loading with itertools in python"
Dior
23 Jan 2016
1 import itertools
2 import threading
3 import time
4 import sys
5
6 done = False
7 '|', '/', '-', '\\'
8 def animate():
9     for c in itertools.cycle(['|', '/', '-', '\\']):
10         if done:
11             break
12         sys.stdout.write('\rAnything You Want Here' + c)
13         sys.stdout.flush()
14         time.sleep(0.1)
15     sys.stdout.write('\rAnything Here To Run After 1 Second. Note 0.1 = 1 second     ')
16
17 t = threading.Thread(target=animate)
18 t.start()
19
20 #long process here
21 time.sleep(10)
22 done = True