Wednesday, May 18, 2005

timeout with threading

I'd gotten the impression that python's threading module was a very frightening thing, and had put off getting to know it. That's too bad, because when I finally looked at it, it provided a very simple way to add timeouts to some of my code. And - unlike os.fork(), etc. - it works on Windows!

t = threading.Thread(target=self.code)
t.start()
t.join(self.timeout)
if t.isAlive():
completed = False
self.msg = 'Timed out after %s seconds' % (self.timeout)
if self.killOnTimeout:
t._Thread__stop()

1 comment:

Anonymous said...

Hi.

Nice site design. Okay, I need your advice.
So, I wanna make my secondary school site, and I am looking for site template.
Can you advice some online place or other resource where I can find many site templates?

It would be better if it will be free:)
I think many of us have personal sites, do you design it yourself?

Thanks a lot, Bill.