Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in atexit._run_exitfuncs [...] Exception expected for value, str found #54965

Closed
kaizhu mannequin opened this issue Dec 22, 2010 · 11 comments
Closed

Error in atexit._run_exitfuncs [...] Exception expected for value, str found #54965

kaizhu mannequin opened this issue Dec 22, 2010 · 11 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@kaizhu
Copy link
Mannequin

kaizhu mannequin commented Dec 22, 2010

BPO 10756
Nosy @birkenfeld, @mdickinson, @pitrou, @vstinner, @merwok, @Trundle
Files
  • issue10756_normalize_exceptions.diff
  • issue10756_normalize_exceptions_v2.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/pitrou'
    closed_at = <Date 2011-05-15.17:06:34.699>
    created_at = <Date 2010-12-22.07:58:30.310>
    labels = ['interpreter-core', 'type-bug']
    title = 'Error in atexit._run_exitfuncs [...]  Exception expected for value, str found'
    updated_at = <Date 2011-05-15.17:06:34.698>
    user = 'https://bugs.python.org/kaizhu'

    bugs.python.org fields:

    activity = <Date 2011-05-15.17:06:34.698>
    actor = 'vstinner'
    assignee = 'pitrou'
    closed = True
    closed_date = <Date 2011-05-15.17:06:34.699>
    closer = 'vstinner'
    components = ['Interpreter Core']
    creation = <Date 2010-12-22.07:58:30.310>
    creator = 'kaizhu'
    dependencies = []
    files = ['20163', '20246']
    hgrepos = []
    issue_num = 10756
    keywords = ['patch']
    message_count = 11.0
    messages = ['124490', '124643', '124670', '124673', '125248', '125249', '125405', '136013', '136015', '136038', '136040']
    nosy_count = 8.0
    nosy_names = ['georg.brandl', 'mark.dickinson', 'pitrou', 'vstinner', 'eric.araujo', 'kaizhu', 'Trundle', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue10756'
    versions = ['Python 3.2']

    @kaizhu
    Copy link
    Mannequin Author

    kaizhu mannequin commented Dec 22, 2010

    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 bpo-5089, 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()

    @kaizhu kaizhu mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 22, 2010
    @Trundle
    Copy link
    Mannequin

    Trundle mannequin commented Dec 25, 2010

    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.

    @merwok
    Copy link
    Member

    merwok commented Dec 26, 2010

    Looks good to me. I’d just move the raising function into the test method (no need to update the patch).

    @birkenfeld
    Copy link
    Member

    +1.

    @Trundle
    Copy link
    Mannequin

    Trundle mannequin commented Jan 3, 2011

    So I guess someone should feel responsible and commit that patch. For convenience, I updated the patch to inline the raise.

    @birkenfeld
    Copy link
    Member

    I think Antoine might be interested.

    @vstinner
    Copy link
    Member

    vstinner commented Jan 5, 2011

    Commited as r87755+r87758. Wait for the buildbot before backporting to other versions.

    @kaizhu
    Copy link
    Mannequin Author

    kaizhu mannequin commented May 15, 2011

    should this bug b closed? it seems fixed in python3.2 for me.

    @birkenfeld
    Copy link
    Member

    Well, Victor still wanted to backport it.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 15, 2011

    New changeset 461e37a60187 by Victor Stinner in branch '3.1':
    Issue bpo-10756: atexit normalizes the exception before displaying it. Patch by
    http://hg.python.org/cpython/rev/461e37a60187

    @vstinner
    Copy link
    Member

    Oh, I forgot the issue. I backported the fix to Python 3.1. Python 2.7 doesn't have the bug.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants