This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: assertion failed when passing an exception object to sys.exit
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: larry, ncoghlan, python-dev, vstinner, xdegaye
Priority: release blocker Keywords:

Created on 2014-02-03 13:07 by xdegaye, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (8)
msg210123 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2014-02-03 13:07
The following code crashes python with:

python: Objects/object.c:512: PyObject_Str: Assertion `!PyErr_Occurred()' failed.

on the tip of the default branch, but not on python 3.3.3.


import sys

error = None
try:
    raise ValueError('some text')
except ValueError as err:
    error = err

if error:
    sys.exit(error)
msg210706 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-09 00:47
New changeset e7708864a8d5 by Nick Coghlan in branch 'default':
Close #20500: Don't trigger PyObject_Str assertion at shutdown
http://hg.python.org/cpython/rev/e7708864a8d5
msg210707 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-02-09 00:49
Thanks for the report Xavier - 3.4 is a bit fussier about not losing that exception state silently, so the shutdown code simply needed to clear it explicitly after saving it on the local stack.
msg210708 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-02-09 01:00
I also added a versionchanged to PyObject_Str and a note in the Porting section of What's New, as third party extensions could also be affected by this change - it elevates "may silently discard an active exception" to "debug build assertion failure".
msg210710 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-09 01:44
"I also added a versionchanged to PyObject_Str and a note in the Porting section of What's New, as third party extensions could also be affected by this change - it elevates "may silently discard an active exception" to "debug build assertion failure"."

Hi, I added this check in many other functions: PyEval_EvalFrameEx(), PyEval_CallObjectWithKeywords(), PyObject_Repr(), PyObject_Str(). And also private methods like type_call().

I added these assertions when I worked on #18408 to ensure that MemoryError exceptions are no more ignored.
msg210711 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-09 02:01
New changeset 41023a501c7b by Nick Coghlan in branch 'default':
Issue #20500: Note other public APIs with the new assertion
http://hg.python.org/cpython/rev/41023a501c7b
msg210712 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-09 02:05
New changeset 9e7594d65178 by Nick Coghlan in branch 'default':
Issue #20500: clarify that invocation may be indirect
http://hg.python.org/cpython/rev/9e7594d65178
msg210713 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2014-02-09 02:06
Above commits added notes for the other two currently documented public APIs directly affected by the change (PyEval_CallObjectWithKeywords isn't currently documented, despite the public name), and also updated the porting note to clarify that these operations may be invoked indirectly via other public APIs.
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64699
2014-02-09 02:06:39ncoghlansetmessages: + msg210713
2014-02-09 02:05:25python-devsetmessages: + msg210712
2014-02-09 02:01:03python-devsetmessages: + msg210711
2014-02-09 01:44:04vstinnersetmessages: + msg210710
2014-02-09 01:00:32ncoghlansetmessages: + msg210708
2014-02-09 00:49:28ncoghlansetmessages: + msg210707
2014-02-09 00:47:12python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg210706

resolution: fixed
stage: needs patch -> resolved
2014-02-09 00:23:42ncoghlansetassignee: ncoghlan

nosy: + ncoghlan
2014-02-03 13:42:32r.david.murraysetpriority: normal -> release blocker
nosy: + vstinner, larry
stage: needs patch

versions: - Python 3.5
2014-02-03 13:07:09xdegayecreate