[Tutor] [Q] about threads ...waiting :(
lonetwin
lonetwin@yahoo.com
Tue, 5 Feb 2002 12:37:41 +0530
Hi Jeff, Blake,
Thanx for replying,
On Tuesday 05 February 2002 05:37, Blake Winton wrote:
> * lonetwin <lonetwin@yahoo.com> [020204 00:42]:
> > > I tried placing try-except blocks at different places, but all I got
> > > done was exit the thread and print the message, somehow the other
> > > threads were quite comfortable with the fact that one of them is dead,
> > > they just go about their own business as though nothing has happened
> > > ...
>
> Having thought about this a little bit, I can tell you what I do in
> Java. Have a "ThreadMonitor" class, that gets passed in to each of your
> TestApp classes. Then, when you get the KeyboardInterrupt exception,
> set a boolean flag in the ThreadMonitor (something like
> "everybodyExitNow"), and in your TestApp class, at various points, check
> the value of the "everybodyExitNow" flag, and if it gets set to true,
> exit the function. It's not the cleanest way to do things, but it seems
> to get the job done, and it lets the various threads clean up after
> themselves, which is nice.
Right-O, in fact that's kinda what Kartik suggested. However instead of a
ThreadMonitor class, he initialized a flag within the __init__ for each
thread, which gets checked every once in a while, when a KeyboardInterrupt is
raised, a handler sets the flag for all the threads. It's so simple I feel
dumb I didn't think about it myself (I said that once already (last post),
saying it again just makes me feel dumber !!! :) )
Also, Jeff, thanx for the tip of using a threading.event object, It's like
doing the same thing, using a feature that's built-in. I guess that's the way
I'll go.
> By and large, it's a good thing for each thread to now care that another
> thread dies. No, really... ;)
Yeah, was aware of that, only it seemed like ..ehe ...not a nice thing :)
Thanx A bunch, all u guys
Peace
Steve
--
"Out of register space (ugh)"
-- vi