Maybe i cant do what i want? I want to have 1 thread do w/e it wants and a 2nd thread to recv user input to set the quit flag. using this code i want to enter q anytime to quit or have it timeout after printing hey 6 times
import sys
import threading
import time
class MyThread ( threading.Thread ):
def run (s):
try:
s.wantQuit = 0
while(not s.wantQuit):
print "want input"
button = raw_input()
if button == "q":
s.wantQuit=1
except KeyboardInterrupt:
s.wantQuit = 1
print "abort with KeyboardInterrupt"
print "done mythread"
myThread = MyThread ()
myThread.start()
a=5
while not myThread.wantQuit:
print "hey"
if (a == 0):
break;
a = a-1;
time.sleep(1)
myThread.wantQuit=1
print "main thread done"
what happens is instead of two threads i have the main one printing hey 4/6 times, then a dialog poping up asking for my input and the app being locked up until i enter it. WTF?!
want input
hey
hey
hey
hey
abort with KeyboardInterrupt
done mythread
main thread done
i am using PyScripter (it has debugging), i also tried pydle which doesnt seem to allow me to enter input and locks up eventually after running it once.