467,921 Members | 1,362 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,921 developers. It's quick & easy.

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

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'
Jun 27 '08 #1
  • viewed: 1708
Share:
1 Reply
On May 26, 2:26*pm, "Grzegorz KokosiŮski" <g.kokosin...@gmail.com>
wrote:
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'
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.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Elf M. Sternberg | last post: by
2 posts views Thread by lpw | last post: by
11 posts views Thread by Jackie | last post: by
2 posts views Thread by gnutuxy | last post: by
7 posts views Thread by Adrian Casey | last post: by
10 posts views Thread by Udai Kiran | last post: by
5 posts views Thread by Yves Dorfsman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.