Signal handler doesn`t handle any signals while main thread is blocked

Signal handler doesn`t handle any signals while main thread is blocked

Post by Grzegorz K » Tue, 27 May 2008 21:26:15


Hi!
I waste a lot of my time figuring why this snip of code doesn`t work.
And still without any solution ;/
Does anybody know why this handler cannot handle SIGINT signal? What
did I wrong?

Thanks in advance.

#
# CODE
#
import signal
from threading import *

def siginthandler(signum, frame):
global work,cv
print 'terminating...'
cv.acquire()
work = 0
cv.notifyAll ()
cv.release()

work = 1
signal.signal (signal.SIGINT, siginthandler)

print 'wait for SIGINT signal'
cv = Condition ()
cv.acquire()
while work:
print 'waiting...'
cv.wait()
print 'woke up'
cv.release()

print 'terminated'
 
 
 

Signal handler doesn`t handle any signals while main thread is blocked

Post by Chri » Tue, 27 May 2008 22:20:37

On May 26, 2:26m, "Grzegorz Kokosiki" < XXXX@XXXXX.COM >

> lobal work,cv> > rint 'terminating..>'
> v.acqui>e()
> o>k = 0
> v.noti>yAll ()
> v>re>ease()
>
> signal.signal (signal.SIGINT, sigi>th>ndler)
>
> print 'wait for SIGI>T signal'
> cv = Co>dition ()
> cv>acquire()
> w>ile work:
> print >waiting...'
>>cv.wait()
> p>int 'woke up'
>
> print 'terminated'

change cv.wait() to cv.wait(delay) and it will capture the terminate
request and wrap the cv.wait(delay) in a try/except IOError: break
block.