Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Threads problem
#1
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
Reply
#2
Remove the call to worker() at line 14.
svalencic likes this post
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Perfect, it works now! Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem to use multi-threads in a code for telnet sessions anna 6 7,256 Jun-27-2018, 10:02 AM
Last Post: anna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020