Is it possible to kill a thread ?

Grant Edwards grante at visi.com
Thu Dec 6 21:14:53 CET 2001


In article <3C0FCD72.A5FA167C at ccvcorp.com>, Jeff Shannon wrote:
> 
> guignot wrote:
> 
>> I have a prog which launches a server, using thread.start_new
>> call. When I destroy the gui, it keeps stuck, probably because
>> the server thread is still running... Can the main prog cleanly
>> die, or is there a way to kill the thread ?
> 
> Create a threading.Event object, and pass it to the thread at startup.  When
> you want to close the application, set the event, and then join() the thread.
> In the thread, you periodically check the event.  When the event becomes set,
> then the thread terminates itself.  At that point, your main thread returns
> from join() and you can finish shutting down.

The problem with this is that one often creates a thread so
that it can do some possibly blocking operation without
stopping the rest of the program.  If the thread is blocked, it
can't check the event.  If the thread isn't going to block,
then why create a thread?  [Yes, there are other reasons for
splitting something into a thread, but in many cases I create a
thread specifically because it's goign to block.]

-- 
Grant Edwards                   grante             Yow!  .. are the STEWED
                                  at               PRUNES still in the HAIR
                               visi.com            DRYER?



More information about the Python-list mailing list