1import time
2import sys
3
4done = 'false'
5#here is the animation
6def animate():
7 while done == 'false':
8 sys.stdout.write('\rloading |')
9 time.sleep(0.1)
10 sys.stdout.write('\rloading /')
11 time.sleep(0.1)
12 sys.stdout.write('\rloading -')
13 time.sleep(0.1)
14 sys.stdout.write('\rloading \\')
15 time.sleep(0.1)
16 sys.stdout.write('\rDone! ')
17
18animate()
19#long process here
20done = 'false'
1import itertools
2import threading
3import time
4import sys
5
6done = False
7#here is the animation
8def animate():
9 for c in itertools.cycle(['|', '/', '-', '\\']):
10 if done:
11 break
12 sys.stdout.write('\rloading ' + c)
13 sys.stdout.flush()
14 time.sleep(0.1)
15 sys.stdout.write('\rDone! ')
16
17t = threading.Thread(target=animate)
18t.start()
19
20#long process here
21time.sleep(10)
22done = True