Killing threads

ericwoodworth at gmail.com ericwoodworth at gmail.com
Sun Apr 5 05:43:14 CEST 2009


Hi,
     I'm new to python and even newer to threading and it seems as
though I'm missing something fundamental about threads.  Basically I
have a program that looks like this:

class ThreadOne(threading.Thread):
     while 1:
          do stuff

class ThreadTwo(threading.Thread):
     while 1:
          do other stuff


first = ThreadOne()
second = ThreadTwo()

while 1:
    do stuff


The issue that I'm having is...I don't know how to kill this app in
window.  I hit ctrl-c but that only seems to kill one of the threads.
The rest of the app just lingers.  There's got to be a more graceful
way but so far I haven't googled anything up.

I'm using queues to talk between these threads so I could certainly
put some kind of message on the queue that causes the threads to
commit suicide but I'm thinking there's a more built in way to do what
I want.  I'm just not sure what it is.

I'd appreciate it if somebody could point me in the right direction.
Thanks.



More information about the Python-list mailing list