Interrupting a thread...

Aahz Maruch aahz at panix.com
Sun Dec 17 09:41:30 EST 2000


In article <91hqgk$pu0$1 at bob.news.rcn.net>,
David Allen <s2mdalle at titan.vcu.edu> wrote:
>
>I'm writing a program which does some networking, and I have a thread
>that is devoted to grabbing things off of the network so that the
>program won't hang while it is reading data.
>
>The problem is, I also occasionally need to interrupt this data
>fetching operation, so I need a way to either raise an exception in the
>other thread, or otherwise signal to it to stop what it's doing.  Since
>the download thread calls other functions that are not sensitive to the
>data in the original object, I can't check to see if some value has
>changed each time I'm reading in a loop.

Sounds like you should split the download thread into two threads, with
critical section locks to prevent contamination of the data.  The second
thread can use threading.Event() to learn when it's supposed to do work.
-- 
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Using LOCs as a measure of programmer productivity is like estimating the 
productivity of a welder by the amount of acetylene used."  



More information about the Python-list mailing list