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

current_thread() becomes "dummy" thread during shutdown #75697

Closed
pitrou opened this issue Sep 19, 2017 · 10 comments
Closed

current_thread() becomes "dummy" thread during shutdown #75697

pitrou opened this issue Sep 19, 2017 · 10 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Sep 19, 2017

BPO 31516
Nosy @tim-one, @pitrou, @vstinner, @asvetlov, @serhiy-storchaka, @miss-islington
PRs
  • bpo-31516: current_thread() should not return a dummy thread at shutdown #3673
  • [3.6] bpo-31516: current_thread() should not return a dummy thread at shutdown (GH-3673) #3856
  • bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds #8052
  • [3.7] bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052) #9813
  • [3.6] bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052) #9814
  • Files
  • mainthread.py
  • 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 2017-10-02.15:20:39.908>
    created_at = <Date 2017-09-19.11:33:54.534>
    labels = ['3.7', 'type-bug', 'library']
    title = 'current_thread() becomes "dummy" thread during shutdown'
    updated_at = <Date 2018-10-12.08:54:24.047>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2018-10-12.08:54:24.047>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-02.15:20:39.908>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2017-09-19.11:33:54.534>
    creator = 'pitrou'
    dependencies = []
    files = ['47152']
    hgrepos = []
    issue_num = 31516
    keywords = ['patch']
    message_count = 10.0
    messages = ['302515', '302517', '302637', '302641', '303537', '303542', '303543', '327572', '327573', '327575']
    nosy_count = 6.0
    nosy_names = ['tim.peters', 'pitrou', 'vstinner', 'asvetlov', 'serhiy.storchaka', 'miss-islington']
    pr_nums = ['3673', '3856', '8052', '9813', '9814']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31516'
    versions = ['Python 3.6', 'Python 3.7']

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 19, 2017

    Attaching reproducer. During interpreter shutdown, threading.main_thread() gets marked "stopped" (while it's obviously still running), while threading.current_thread() returns a DummyThread instance with the same ident as the main thread.

    $ ./python mainthread.py 
    -- before shutdown --
    GC in thread <_MainThread(MainThread, started 140359122872064)>
    main thread is <_MainThread(MainThread, started 140359122872064)>
    -- during shutdown --
    GC in thread <_DummyThread(Dummy-1, started daemon 140359122872064)>
    main thread is <_MainThread(MainThread, stopped 140359122872064)>

    @pitrou pitrou added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Sep 19, 2017
    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 19, 2017

    The main thread being marked "stopped" at shutdown might be an obscure feature (as hinted in the comments for threading._shutdown()). However, current_thread() should definitely not return a separate DummyThread instance.

    @pitrou
    Copy link
    Member Author

    pitrou commented Sep 20, 2017

    Tim, any opinion on this one? Do you agree it's an actual bug (if a bit obscure)?

    @tim-one
    Copy link
    Member

    tim-one commented Sep 20, 2017

    Ya, it's clearly best for current_thread() to deliver consistent results.

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 2, 2017

    New changeset 1023dbb by Antoine Pitrou in branch 'master':
    bpo-31516: current_thread() should not return a dummy thread at shutdown (bpo-3673)
    1023dbb

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 2, 2017

    New changeset ac6245a by Antoine Pitrou (Miss Islington (bot)) in branch '3.6':
    [3.6] bpo-31516: current_thread() should not return a dummy thread at shutdown (GH-3673) (bpo-3856)
    ac6245a

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 2, 2017

    I have now pushed the fix to master and 3.6. Hopefully this won't break anyone's code...

    @pitrou pitrou closed this as completed Oct 2, 2017
    @serhiy-storchaka
    Copy link
    Member

    New changeset 65d2f8c by Serhiy Storchaka (Zackery Spytz) in branch 'master':
    bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
    65d2f8c

    @miss-islington
    Copy link
    Contributor

    New changeset c327a54 by Miss Islington (bot) in branch '3.7':
    bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
    c327a54

    @miss-islington
    Copy link
    Contributor

    New changeset d918e98 by Miss Islington (bot) in branch '3.6':
    bpo-31516: Skip test_main_thread_during_shutdown() with COUNT_ALLOCS builds. (GH-8052)
    d918e98

    @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 stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants