473,785 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sigNu m, execFrame):
print "Interrupted,,, "
sys.exit(sigNum )

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

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

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


The error:

../test
success
( pressing Ctrl-C )
Interrupted,,,
Exception exceptions.Syst emExit: 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 1132

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

Similar topics

2
3968
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 explicitly raises a SystemExit exception. My understanding is that the C-level I/O code will continue and the signal won't be processed until the end of the atomic python interpreter instruction that invoked that C code.
2
2228
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 creating modules that have a member function 'write' or 'readline' respectively and assigning them to sys.stdin and sys.stdout.
2
3936
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 we are registering for, and a second parameter that is the function to call. What I want to do is specify the function to call as a function of an instance of "this" class e.g.
7
2214
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 similiar to the concept of try-catch to me.) It seems to relate more to nix OS. Are signals handling part of Windows too?
0
1370
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 pool. RunScript(pScriptName,pFuncName,...) { PyEval_AcquireLock() threadState = Py_NewInterpreter(); PyThreadState_Swap(threadState);
10
4035
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 finished, control does not return to the printf statement in main() which is present after the strcpy statement. Instead Segmentation violation error message is printed in Redhat Linux and the program is aborted. In VC++, the SIGSEGV_handler is...
1
4819
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 working". I've searched the forums here, but could not find anything particular to my problem, Googling and the linux manual pages haven't been much help either. What the program is supposed to do is create a very simple shell (that sits atop the...
0
893
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: '/usr/lib/python2.4/lib-dynload/timemodule.so: undefined symbol: PyModule_AddObject' in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection Aborted
0
842
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
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.