classification
Title: Error in atexit._run_exitfuncs [...] Exception expected for value, str found
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pitrou Nosy List: Trundle, eric.araujo, georg.brandl, kaizhu, mark.dickinson, pitrou, python-dev, vstinner
Priority: normal Keywords: patch

Created on 2010-12-22 07:58 by kaizhu, last changed 2011-05-15 17:06 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
issue10756_normalize_exceptions.diff Trundle, 2010-12-25 17:20 review
issue10756_normalize_exceptions_v2.diff Trundle, 2011-01-03 21:56 review
Messages (11)
msg124490 - (view) Author: kai zhu (kaizhu) Date: 2010-12-22 07:58
public@colinux 3 ~: python3.2
Python 3.2b2 (py3k, Dec 22 2010, 02:38:55) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import atexit; atexit.register(lambda:1/0)
<function <lambda> at 0xb7c7e12c>
>>> exit()
Error in atexit._run_exitfuncs:
TypeError: print_exception(): Exception expected for value, str found



might b related to Issue5089, so included those ppl to nosy.  this bug is subtle.  unit tests which explicitly 'raise' exceptions will not b caught, e.g. this will raise properly:

@exit.register
def foo(): raise ZeroDivisionError()
msg124643 - (view) Author: Andreas Stührk (Trundle) * Date: 2010-12-25 17:20
It's because `PyErr_Fetch()` which is used in `atexit_callfuncs()` can return an unnormalized exception (e.g. if the exception is set with `PyErr_SetString()`. "value" is then a string). A simple call to `PyErr_NormalizeException()` fixes this issue.

Attached is a patch which fixes the issue and adds a test for it. I used exactly the same code ("1 / 0") to raise the exception, as I don't know if there is some clean way to raise an unnormalized exception.
msg124670 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-12-26 18:00
Looks good to me.  I’d just move the raising function into the test method (no need to update the patch).
msg124673 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-26 19:04
+1.
msg125248 - (view) Author: Andreas Stührk (Trundle) * Date: 2011-01-03 21:56
So I guess someone should feel responsible and commit that patch. For convenience, I updated the patch to inline the raise.
msg125249 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-01-03 22:18
I think Antoine might be interested.
msg125405 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-01-05 03:57
Commited as r87755+r87758. Wait for the buildbot before backporting to other versions.
msg136013 - (view) Author: kai zhu (kaizhu) Date: 2011-05-15 07:41
should this bug b closed? it seems fixed in python3.2 for me.
msg136015 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2011-05-15 07:53
Well, Victor still wanted to backport it.
msg136038 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011-05-15 17:02
New changeset 461e37a60187 by Victor Stinner in branch '3.1':
Issue #10756: atexit normalizes the exception before displaying it. Patch by
http://hg.python.org/cpython/rev/461e37a60187
msg136040 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-05-15 17:06
Oh, I forgot the issue. I backported the fix to Python 3.1. Python 2.7 doesn't have the bug.
History
Date User Action Args
2011-05-15 17:06:34vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg136040
2011-05-15 17:02:40python-devsetnosy: + python-dev
messages: + msg136038
2011-05-15 07:53:36georg.brandlsetmessages: + msg136015
2011-05-15 07:41:58kaizhusetmessages: + msg136013
2011-01-05 03:57:15vstinnersetnosy: + vstinner
messages: + msg125405
2011-01-03 22:18:32georg.brandlsetassignee: pitrou

messages: + msg125249
nosy: + pitrou
2011-01-03 21:56:01Trundlesetfiles: + issue10756_normalize_exceptions_v2.diff
nosy: georg.brandl, mark.dickinson, eric.araujo, kaizhu, Trundle
messages: + msg125248
2010-12-26 19:04:12georg.brandlsetnosy: + georg.brandl
messages: + msg124673
2010-12-26 18:00:01eric.araujosetnosy: + eric.araujo

messages: + msg124670
stage: patch review
2010-12-25 17:20:19Trundlesetfiles: + issue10756_normalize_exceptions.diff

nosy: + Trundle
messages: + msg124643

keywords: + patch
2010-12-24 21:48:33terry.reedysetnosy: - BreamoreBoy
2010-12-22 07:58:30kaizhucreate