2
I’m trying to run two threads where one is an animation of loading, and the other a print, but when finished executing the thread work which is the print, the loading keeps running, I’d like it to finish as soon as the print is done
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! ')
def work():
print('\nexecutado, finalizando o loading')
#long process here
done = True
load = threading.Thread(target=animate)
load.start()
worker = threading.Thread(target=work)
worker.start()
Thank you very much brother, I was not seeing the error! :)
– Luis Henrique
Beauty bro! When things like this happen, you can either check how it works using your IDE’s Debugger, or test how the code works line by line, initially printing all the dubious states.
– Absolver
thanks for the tip!!
– Luis Henrique