Killing a thread

Felipe Almeida Lessa felipe.lessa at gmail.com
Fri Jun 9 17:50:27 EDT 2006


Em Sex, 2006-06-09 às 13:54 -0700, Manish Marathe escreveu:
> On 6/9/06, Fredrik Lundh <fredrik at pythonware.com> wrote:
>         Manish Marathe wrote:
>         
>         > I am creating threads using my self defined class which
>         inherits the
>         > threading.Thread class. I want to know how can I kill the
>         threads which
>         > are being created by the object of my self defined class. 
>         
>         you cannot kill a thread "from the outside"; you have to
>         design your
>         thread tasks so they can kill themselves, when asked to do
>         that.
> 
> Thanks for the reply. So can a thread listen to an event i.e. can we
> send an event to the thread indicating to kill itself.

A plain simple boolean flag will certainly do the job. For example

    def run(self):
        self.running = True
        while self.running:
            blah()

    def stop(self):
        self.running = False
        

-- 
Felipe.




More information about the Python-list mailing list