msg139319 - (view) |
Author: Kamil Kisiel (kisielk) |
Date: 2011-06-27 17:52 |
It seems that registering a signal handler for SIGABRT doesn't handle the signal from os.abort(). Example code: import signal, os import time def handler(signum, frame): print "Signal!" raise Exception() signal.signal(signal.SIGABRT, handler) os.abort() The result is the process still core dumps instead of raising an exception. If instead of os.abort I call time.sleep(10) and then send a kill -ABRT from a shell, the exception is raised as expected. I tried this with Python 2.6 on Gentoo, 2.7 on FC 14, and 2.6 on OS X 10.6.7 with the same result. Based on the documentation for os.abort, I would expect this to work: Generate a SIGABRT signal to the current process. On Unix, the default behavior is to produce a core dump; on Windows, the process immediately returns an exit code of 3. Be aware that programs which use signal.signal() to register a handler for SIGABRT will behave differently. |
|
|
msg139328 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-06-27 21:44 |
Extract of abort manual page: "The abort() first unblocks the SIGABRT signal, and then raises that signal for the calling process. This results in the abnormal termination of the process unless the SIGABRT signal is caught and the signal handler does not return (see longjmp(3))." If you use a Python signal handler, you have to know that the signal is first handled in C. The Python callback is called "later". In your example, the C signal handler is called, but it *returns* and so the process is stopped. Python exceptions are not implemented using longjmp() but using a global variable (storing the exception object) and functions return NULL, so I don't think that you can handle the abort() in Python. > If instead of os.abort I call time.sleep(10) > and then send a kill -ABRT from a shell, the exception > is raised as expected. Yes, this is different from abort() (read again abort() manual page, at least its Linux manpage). -- abort() is really a corner case of signal handling. You have better to avoid abort() in your application, instead of trying to handle it. By the way, what do you want to do on abort()? If you enable faulthandler, you get the Python traceback on abort(). |
|
|
msg139376 - (view) |
Author: Kamil Kisiel (kisielk) |
Date: 2011-06-28 21:00 |
The application is interfacing with a C library that uses abort() to signal fatal errors (horrible, I know..). Instead of core dumping I would like to be able to handle these errors at the Python level and do something else. It's starting to sound like that might be impossible. You explanation of the abort() behaviour makes sense to me. However, if that's the case then this portion of the docs appears to be incorrect: "Be aware that programs which use signal.signal() to register a handler for SIGABRT will behave differently." Maybe my interpretation is wrong, but I would read "behave differently" as "call the signal handler instead" in this case. |
|
|
msg139378 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-06-28 21:53 |
"Be aware that programs which use signal.signal() to register a handler for SIGABRT will behave differently." I don't understand this sentence. I think that this sentence should be removed, and another should maybe be added. E.g. "os.abort() doesn't call the Python signal handler installed by signal.signal()." |
|
|
msg139796 - (view) |
Author: Kamil Kisiel (kisielk) |
Date: 2011-07-04 17:59 |
Here's my proposed patch for the documentation, against the head of the 2.7 branch. |
|
|
msg140008 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2011-07-08 00:27 |
New changeset 1ac21a715c5d by Victor Stinner in branch '2.7': Issue #12423: Fix os.abort() documentation http://hg.python.org/cpython/rev/1ac21a715c5d New changeset 4e83d8f6d496 by Victor Stinner in branch '3.2': Issue #12423: Fix os.abort() documentation http://hg.python.org/cpython/rev/4e83d8f6d496 New changeset e3c115ba8dc0 by Victor Stinner in branch 'default': (merge 3.2) Issue #12423: Fix os.abort() documentation http://hg.python.org/cpython/rev/e3c115ba8dc0 |
|
|
msg140009 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2011-07-08 00:28 |
> Here's my proposed patch for the documentation, against > the head of the 2.7 branch. Thanks, I applied your pach to 2.7, 3.2 and 3.3 doc. |
|
|
msg374117 - (view) |
Author: Howard A. Landman (Howard_Landman) |
Date: 2020-07-23 00:56 |
I don't think changing the documentation makes this not be a bug. My situation: I have a Python 3.7.3 program that reliably dies (after about 13 hours, having called its measure() method between 118.6M and 118.7M times) with free(): invalid pointer, which calls abort(). I believe that this is a bug in Python; and it's NOT a memory leak, since the size of the program doesn't change at all over time and is under 14 MB (real). I would like to debug it. This basically says "you're screwed". I can't catch the abort, and I can't use python3-dbg because it won't bind with the RPi.GPIO or spidev libraries. So all I can get from a core dump is that free() is being called by list_ass_item() at ../Objects/listobject.c line 739. Assuming that I'm right and that this is a bug in Python, how do you expect anyone to ever debug it? At a bare minimum, there needs to be an easy way to get a full stack trace through both Python and C. |
|
|