Hello, I posted this to the tutor list, but didn't get any responses, unless my email client really messed up.  So I'll try here.  <br>
<br>
I'm starting to work with threads, but I'm a little confused.  I think I understand the concepts, but not the controls. Why doesn't something like this work:<br>
<br>
#############<br>
import threading<br>
<br>
def counter(x):<br>
    while tEvent.isSet():<br>
        x+=1<br>
        print x<br>
<br>
def tStart():<br>
    tEvent.set()<br>
    if counterThread.isAlive():<br>
        counterThread.join()<br>
    else:<br>
        counterThread.start()<br>
<br>
def tStop():<br>
    tEvent.clear()<br>
  <br>
counterThread=threading.Thread(target=counter, args=(1,))<br>
tEvent=threading.Event()<br>
<br>
#####################<br>
<br>
After that I have controls setup for a Tkinter box with two buttons, one has<br>
tStart as it's command value, and the other tStop.  When I run the program,<br>
it starts fine, and then the loop stops when I press 'stop', but when I try<br>
to press 'start' again, I get an error:<br>
<br>
###########<br>
Exception in Tkinter callback<br>
Traceback (most recent call last):<br>
  File "C:\myweb\python\lib\lib-tk\Tkinter.py", line 1345, in __call__<br>
    return self.func(*args)<br>
  File "C:\myweb\python\SNC\Script1.py", line 14, in tStart<br>
    counterThread.start()<br>
  File "C:\myweb\python\lib\threading.py", line 404, in start<br>
    assert not self.__started, "thread already started"<br>
AssertionError: thread already started<br>
############<br>
<br>
Because my 'while' func depends on the flag, when the flag is false, and it stops, the thread should die, right?<br>
<br>
And why the need for the extra comma in the args value when defining my<br>
instance?<br>
<br>
-Stryder<br>