By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,550 Members | 874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,550 IT Pros & Developers. It's quick & easy.

Joining threads but allowing signals to main thread?

P: n/a
I have a python-2.5 program running under linux in which I spawn a
number of threads. The main thread does nothing while these subsidiary
threads are running, and after they all complete, the main thread will
then exit.

I know that I can manage this through the use of Thread.join(), but
when I do it as follows, the main thread doesn't respond to signals:

import sys, time, signal, threading

signaled = False

class Signaled(Exception):

def sighandler(signum, frame):
global signaled
print 'aborted!'
signaled = True

def sigtest():
global signaled
if signaled:
raise Signaled

def myfunc(arg):
while True:
# do something
except Signaled:

threads = []
for a in sys.argv[1:]:
t = threading.Thread(myfunc, args=(a,))

# do some initialization

for s in (signal.SIGHUP, \
signal.SIGINT, \
signal.SIGQUIT, \
signal.signal(s, sighandler)

for t in threads:

for t in threads:


However, if I get rid of the t.join() loop and replace the last three
executable lines of the program with these, the main thread responds to
signals just fine:


while threading.activeCount() 1:


Is there any way to allow my program to respond to signals without
having to busy-wait in the main thread?

Thanks in advance.
Lloyd Zusman
God bless you.

Jan 11 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.