Killing a running thread

Michael Gilfix mgilfix at eecs.tufts.edu
Thu May 2 10:09:11 EDT 2002


  In Python you need to break your loops up into chunks and check a
have a threading.Event () object that you check if set. So something
like:

     done = threading.Event ()

     line = file.readline ()
     while line and not done.isSet ():
        # do stuff
        line = file.readline ()

   Or..

    for line in file.xreadlines ():
       if done.isSet ():
         break


                 -- Mike

On Thu, May 02 @ 15:12, Alexander Skwar wrote:
> Okay, I'll send this reply back to the group.
> 
> However, I'm sorry to say this, but this didn't help me.  My problem is,
> that I'm spending a very large time in just one map() function call,
> which iterates over a large list and calls a custom method for every
> element.   I could of course write a thread wrapper function for this
> function, but this doesn't sound very elegant to me.  Further, even if
> I'd do this, I wouldn't know how I could jump out of this function
> without iterating over the rest of the elements.
> 
> Other large amounts of time are spend in a "for zeile in
> xreadlines.xreadlines(src):".  Here I could of course use the techniques
> from your link.  And finally I'm spending a large chunk of time in
> md5s.write(result_str_md5) (md5s is a file object).  For this I would
> not know how I could quit the thread at all.
> 
> Alexander Skwar
> -- 
> How to quote:	http://learn.to/quote (german) http://quote.6x.to (english)
> Homepage:	http://www.iso-top.de      |    Jabber: askwar at a-message.de
>    iso-top.de - Die günstige Art an Linux Distributionen zu kommen
>                        Uptime: 8 days 8 hours 5 minutes
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
`-> (ASkwar)

-- 
Michael Gilfix
mgilfix at eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html





More information about the Python-list mailing list