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

Script globals in a GC cycle not finalized when exiting with SystemExit #68784

Closed
encukou opened this issue Jul 9, 2015 · 6 comments
Closed
Labels
3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@encukou
Copy link
Member

encukou commented Jul 9, 2015

BPO 24596
Nosy @ncoghlan, @pitrou, @encukou, @ZackerySpytz
PRs
  • bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit #7918
  • [3.6] bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918) #8069
  • [3.7] bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918) #8070
  • 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 = None
    closed_at = <Date 2018-07-03.20:18:03.556>
    created_at = <Date 2015-07-09.13:31:32.739>
    labels = ['interpreter-core', '3.7', '3.8']
    title = 'Script globals in a GC cycle not finalized when exiting with SystemExit'
    updated_at = <Date 2018-07-03.20:18:03.555>
    user = 'https://github.com/encukou'

    bugs.python.org fields:

    activity = <Date 2018-07-03.20:18:03.555>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-07-03.20:18:03.556>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2015-07-09.13:31:32.739>
    creator = 'petr.viktorin'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 24596
    keywords = ['patch']
    message_count = 6.0
    messages = ['246491', '246498', '246502', '321001', '321003', '321004']
    nosy_count = 4.0
    nosy_names = ['ncoghlan', 'pitrou', 'petr.viktorin', 'ZackerySpytz']
    pr_nums = ['7918', '8069', '8070']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue24596'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @encukou
    Copy link
    Member Author

    encukou commented Jul 9, 2015

    When this program is invoked as a script (python reproducer.py), the del is never called:

    ---

    class ClassWithDel:
        def __del__(self):
            print('__del__ called')
    
    a = ClassWithDel()
    a.link = a
    
    raise SystemExit(0)

    Raising a different exception, moving the code to a function, importing the module, or invoking with -m (or even -c), causes __del__ to be called normally.

    @encukou encukou added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 9, 2015
    @pitrou
    Copy link
    Member

    pitrou commented Jul 9, 2015

    It's likely that your global variable gets caught in the traceback attached to the SystemExit, and that either never gets deallocated, or gets deallocated too late.

    @pitrou
    Copy link
    Member

    pitrou commented Jul 9, 2015

    Actually, the problem is in PyRun_SimpleFileExFlags(). The executed module is decref'ed after calling PyErr_Print(), but the latter never returns when the exception is a SystemExit.

    @ZackerySpytz ZackerySpytz mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Jun 25, 2018
    @pitrou
    Copy link
    Member

    pitrou commented Jul 3, 2018

    New changeset d8cba5d by Antoine Pitrou (Zackery Spytz) in branch 'master':
    bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918)
    d8cba5d

    @pitrou
    Copy link
    Member

    pitrou commented Jul 3, 2018

    New changeset 20ae4c6 by Antoine Pitrou (Miss Islington (bot)) in branch '3.7':
    bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918) (GH-8070)
    20ae4c6

    @pitrou
    Copy link
    Member

    pitrou commented Jul 3, 2018

    New changeset e1ebf51 by Antoine Pitrou (Miss Islington (bot)) in branch '3.6':
    bpo-24596: Decref module in PyRun_SimpleFileExFlags() on SystemExit (GH-7918) (GH-8069)
    e1ebf51

    @pitrou pitrou closed this as completed Jul 3, 2018
    @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
    3.7 (EOL) end of life 3.8 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs)
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants