[Tutor] [Q] about threads ...waiting :(
lonetwin
lonetwin@yahoo.com
Mon, 4 Feb 2002 11:08:07 +0530
Hi All,
....ehe...I hate to do this, but since I did not get an answer I'm reposting
this. If some thing of this sort is not possible, then could someone please
suggest a workaround/hack ??
Thanx
Steve
On Saturday 02 February 2002 16:43, lonetwin wrote:
> Hi everybody,
> I'm playing around with threads using python on linux. Everthing is
> working fine ...but (everything seems to have a "but" ...right ?? :)) I
> can't seem to print a nice message and end the application, if there
> is a KeyboardInterrupt generated.
> As always I find saying things in code easier than expressing them
> in plain english, so here goes:
>
> within my main I have something like:
> =========================================
> for i in range(numThreads):
> TestThread = TestApp(var, SharedLock)
> ThreadList.append(TestThread)
>
> for TestThread in ThreadList:
> TestThread.start()
>
> while threading.activeCount() > 1:
> pass
>
> doCleanUp()
>
> =========================================
> ...and the class TestApp has something like:
> =========================================
> def run(self):
> self.lock.acquire()
> doStuff()
> self.lock.release()
> ==========================================
> Now, if a KeyboardInterrupt exception is raised during the execution of
> doStuff(), how do I catch it, kill all the threads and exit the
> application, probably printing "Aieee ....I got killed" on the way ??
>
> 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 ...
>
> ......and like always, I'm going nuts, b'cos ...
> ...I just don't get it !!!!
>
> any help would be welcome,
>
> Peace
> Steve
--
America works less, when you say "Union Yes!"