signal and threading

L

~levon

Hello group,

in following example, a signal handler is registered and a thread
started. if I call self.doSomethin() directly
the code works as I would expect. as i send a SIGINT shutdown is
called and the script terminates.

as soon as I call doSomething() in a thread the the SIGINT handler is
never called again and
i have to terminate the script with a SIGTERM or SIGKILL.

well, i would expect the handler to be called in both cases, am i
missing something?

by the way. calling os.kill(os.getpid(), signal.SIGINT) works as I
would expect, what
don't is kill -s SIGINT pid # where pid is the actual process id

the code:

class Runner(object):
def __init__(self):
print os.getpid()
self.shd = False
signal.signal(signal.SIGINT, self.shutdown)
threading.Thread(target=self.doSomething).start()
# the following works fine:
#os.kill(os.getpid(), signal.SIGINT)

def doSomething(self):
while not self.shd:
pass

def shutdown(self, signo, frm):
self.shd = True

if __name__ == '__main__':
Runner()

~levon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top