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

test_no_refcycle_through_target sometimes fails in test_threading #46748

Closed
pitrou opened this issue Mar 27, 2008 · 8 comments
Closed

test_no_refcycle_through_target sometimes fails in test_threading #46748

pitrou opened this issue Mar 27, 2008 · 8 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@pitrou
Copy link
Member

pitrou commented Mar 27, 2008

BPO 2496
Nosy @pitrou
Files
  • test_threading.patch
  • test_threading2.patch
  • 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 2008-03-28.04:12:52.791>
    created_at = <Date 2008-03-27.12:04:29.607>
    labels = ['type-bug', 'library']
    title = 'test_no_refcycle_through_target sometimes fails in test_threading'
    updated_at = <Date 2008-03-28.04:12:52.789>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2008-03-28.04:12:52.789>
    actor = 'jyasskin'
    assignee = 'jyasskin'
    closed = True
    closed_date = <Date 2008-03-28.04:12:52.791>
    closer = 'jyasskin'
    components = ['Library (Lib)']
    creation = <Date 2008-03-27.12:04:29.607>
    creator = 'pitrou'
    dependencies = []
    files = ['9874', '9878']
    hgrepos = []
    issue_num = 2496
    keywords = ['patch']
    message_count = 8.0
    messages = ['64584', '64586', '64596', '64600', '64602', '64608', '64612', '64614']
    nosy_count = 3.0
    nosy_names = ['nnorwitz', 'pitrou', 'jyasskin']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2496'
    versions = ['Python 2.6']

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 27, 2008

    This is a reminder for the failing test which is affecting some buildbots.
    I can't reproduce it right now (under Linux), even by surrounding the
    test code with a pair of gc.disable() / gc.enable().

    @pitrou pitrou added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 27, 2008
    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 27, 2008

    This is a tentative patch. I can't verify it fixes anything but at least
    it shouldn't do any harm ;)
    If it doesn't fix it I see two possible explanations:

    • the buildbots are running some kind of debug build which keeps
      references to local variables, preventing them to be deallocated
    • the C thread implementation needs fixing on some platforms

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 27, 2008

    Hmm, even with a Py_DEBUG build I can't reproduce the bug.

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 27, 2008

    Hmm, I think I know what happens. t_bootstrap() in threadmodule.c calls
    the self.__bootstrap() method in the Thread object, and it is this
    method which sets the __stopped flag at its end, which in turns wakes up
    the join() method.

    The problem is that at this point, t_bootstrap() still (rightly) holds a
    reference to the Thread object, since it has a reference to its
    __bootstrap() method which is still running. Depending on how the
    operating system switches threads, this reference may or may not be
    released when the join() method returns.

    So I think it's the test that is flaky. Instead of calling the join()
    method, it should wait for the OS-level thread to finish. Or it should
    find another way of testing for the reference cycle.

    @pitrou
    Copy link
    Member Author

    pitrou commented Mar 27, 2008

    I'm attaching a patch which tries to make the test a bit less flaky
    (well, it still is, since I introduce a time.sleep() :-)).

    @jyasskin
    Copy link
    Mannequin

    jyasskin mannequin commented Mar 27, 2008

    I'll look at this tonight.

    @jyasskin jyasskin mannequin self-assigned this Mar 27, 2008
    @jyasskin
    Copy link
    Mannequin

    jyasskin mannequin commented Mar 28, 2008

    I think I've confirmed your diagnosis. If I add a _sleep(.01) to
    Thread.__bootstrap_inner() just after the call to self.__stop(), the
    test fails reliably. Very good catch! Given that, I think just adding a
    short sleep to the test before counting references will fix it nearly
    every time, but I'd like to kill the race dead if we can.

    @jyasskin
    Copy link
    Mannequin

    jyasskin mannequin commented Mar 28, 2008

    Fixed in r61984. I believe the exception info was actually keeping the
    object alive. The thread itself didn't have any references to it, but
    the traceback did.

    @jyasskin jyasskin mannequin closed this as completed Mar 28, 2008
    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant