473,395 Members | 1,652 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,395 software developers and data experts.

Re: Bloody signal handling (in embedded Python code)


Right, I didn't realize before that Python interpreter has its own
signal handling routines.

Now I am able to handle signals in Python code, but it still barfs on exit:

import time
import signal
import sys

def userBreak(sigNum, execFrame):
print "Interrupted,,,"
sys.exit(sigNum)

def terminateRun(sigNum, execFrame):
print "SIGTERM received, terminating."
sys.exit(sigNum)

def test():
time.sleep(1)
print "success"
time.sleep(90)

if __name__ == "__main__":
signal.signal(signal.SIGTERM, terminateRun)
signal.signal(signal.SIGINT, userBreak)
test()


The error:

../test
success
( pressing Ctrl-C )
Interrupted,,,
Exception exceptions.SystemExit: 2 in 'garbage collection' ignored
Fatal Python error: unexpected exception during garbage collection
Aborted
So the real question is - how to exit cleanly from embedded Python code?
Jul 2 '08 #1
0 1104

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary Robinson | last post by:
In some code we're writing we're making an assumption, and I'd like to confirm that the assumption is valid. Suppose a signal arrives while a file is being written, and the signal handler...
2
by: Bertram Scharpf | last post by:
Hi, in one of my C programs, I call embedded Python code. Now, I would like to redirect stdin/stdout to strings I can assign to/read out within the C code. This should be a solvable problem...
2
by: Lionel van den Berg | last post by:
Hi all, I'm trying to do some signal handling using the csignal library but I can't find and specific examples for C++. The signal function as defined in C takes a parameter that is the signal...
7
by: Stanley S | last post by:
Hi, Are Signal Handling part of ANSI C? I am not able to find any reference of Sig Handling in Stephen Prata's "C Primer Plus". The usage of signals is to trap errors I guess. (It looks...
0
by: kiran kumar | last post by:
Hi All, I am working on embedded python on C these days. I feel there is a memory leakage in this code. I have used our own memory pool and all the python code will use the heap from this memory...
10
by: subramanian | last post by:
Consider the following code: segment violation is deliberately generated to catch the SIGSEGV signal. The handler for this signal, namely SIGSEGV_handler, is called. However after the handler is...
1
by: 32Alpha | last post by:
Hi, first post here. First off, this IS a homework assignment for an operating systems class, but the question isn't "how do i do the assignment" but "why is my particular implementation not...
0
by: Marcin Krol | last post by:
Hello everyone, I can embed Python interpreter in C code now, but now there's another problem, importing modules in Python code doesn't work: Exception exceptions.ImportError:...
0
by: Marcin Krol | last post by:
Hello everyone, And now for something completely different: signal handling sometimes works, sometimes it doesn't. When I embed following code, it works: count = 0
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.