Answers for "how to create a loading animation in python while a huge file is loading"

2

loading animation python

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
Posted by: Guest on March-07-2020

Code answers related to "how to create a loading animation in python while a huge file is loading"

Python Answers by Framework

Browse Popular Code Answers by Language