Python Forum

Full Version: Threads problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

I have an issue at running Threads code from this example https://www.youtube.com/watch?v=A_Z1lgZL...LL&index=7 at time 4.20
Here's my code, but sentence "Press enter to exit" doesn't appear and pressing enter doesn't stop the loop:

import threading
import time

done = False

def worker():
    counter = 0
    while not done:
        time.sleep(1)
        counter += 1
        print(counter)

threading.Thread(target=worker).start()
worker()

input("Press enter to exit")
done = True
Remove the call to worker() at line 14.
Perfect, it works now! Thank you!