Killing subservient threads

Gabriel Genellina gagsl-py2 at
Sat Feb 21 05:17:41 CET 2009

En Fri, 20 Feb 2009 16:15:10 -0200, jimzat <jimzat at> escribió:

> I am using the thread module and calling thread.start_new_thread
> (...).  If I use t=thread.start_new_thread(...) and later set
> t.terminate, I get "AttributeError: 'int' object has no attribute
> 'terminate'"

Use the threading module instead, that provides a higher level interface.  
If you originally had:

thread.start_new_thread(function, args)

then it becomes:

polling_thread = threading.Thread(target=function, args=args)

> What is the proper way to do this?  I don't want to use globals as I
> will have multiple child windows of various classes.

Use an attribute of this Thread instance. Either a simple boolean or a  
Condition/Event object as Christian Heimes suggested.

Gabriel Genellina

More information about the Python-list mailing list