[Tutor] [Q] about threads

lonetwin lonetwin <lonetwin@yahoo.com>
Sat, 2 Feb 2002 16:43:58 +0530 (IST)


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
-- 
He who wonders discovers that this in itself is wonder.
		-- M.C. Escher