Skip to content

Instantly share code, notes, and snippets.

@Thanatoz-1
Created August 1, 2018 13:19
Show Gist options
  • Save Thanatoz-1/c906b702e4b7c32bab1fcede972d2399 to your computer and use it in GitHub Desktop.
Save Thanatoz-1/c906b702e4b7c32bab1fcede972d2399 to your computer and use it in GitHub Desktop.
Code for creating loading animation in python script
import itertools
import threading
import time
import sys
done = False
#here is the animation
def animate():
for c in itertools.cycle(['|', '/', '-', '\\']):
if done:
break
sys.stdout.write('\rloading ' + c)
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\rDone! ')
t = threading.Thread(target=animate)
t.start()
#long process here
time.sleep(10)
done = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment