473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
1 2085
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Elf M. Sternberg | last post by:
I'm having a devil of a time with signal handling under BSD 4.4 with Python and I was hoping that this might ring a bell with someone. Using the Webware Application Server (a multi-threaded Python...
2
by: Holger Joukl | last post by:
Hi, migrating from good old python 1.5.2 to python 2.3, I have a problem running a program that features some threads which execute calls to an extension module. Problem is that all of a sudden,...
2
by: lpw | last post by:
I have dilligently reviewed FAQ-lite Section 3.2, "How do I pass a pointer-to-member-function to a signal handler, X event callback, system call that starts a thread/task, etc." The only...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
2
by: gnutuxy | last post by:
Hi, I am newbie in the Unix system programming and in learning phase. I usually read the libc manual and then try to implement small programs to test/check the learnt thing. I read the libc...
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
10
by: Udai Kiran | last post by:
Hi all Iam having trouble with signal handler. Where will the execution return after invoking a signal handler when that particular signal is recieved? will return to the point where we register...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
5
by: Yves Dorfsman | last post by:
I did a few tests with this script: class byebye: def __del__(self): print 'Bye, bye...' x = byebye()
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.