threading module timer object

.d.hos dhostetler at
Tue Feb 4 00:09:02 CET 2003

hello all,
I have a multithreading app, and I want to watch each thread with a
timeout function.

currently, I using the the threading modules timer object, and
try:/except: statements, to raise a user defined exception. The user
defined exception is raised after the said timespan passes, but
processing that occurs after catching the exception never happens.

I think i'm fairly close to getting this working, but can't figure out
what i'm doing wrong here. any input?

class workerThread(threading.Thread):
    def __init__(self, queue, threadNo=None):
        self.__queue = queue
        self.__TimeOut = "Thread timed out"

    def flagIt(self):
        raise self.__TimeOut
    def run(self):
            t = threading.Timer(5.0, self.flagIt)

            #do something here
            self.__queue.put("mission complete")
        except self.__TimeOut:
            self.__queue.put("timeout error")


More information about the Python-list mailing list