Skip to content

test_no_refcycle_through_target sometimes fails in test_threading #46748

Closed

Description

@pitrou
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']

    Activity

    1. pitrou commented on Mar 27, 2008

      @pitrou
      MemberAuthor

      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().

    2. added
      stdlib
      type-bug
      on Mar 27, 2008
    3. pitrou commented on Mar 27, 2008

      @pitrou
      MemberAuthor

      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
    4. pitrou commented on Mar 27, 2008

      @pitrou
      MemberAuthor

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

    5. pitrou commented on Mar 27, 2008

      @pitrou
      MemberAuthor

      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.

    6. pitrou commented on Mar 27, 2008

      @pitrou
      MemberAuthor

      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() :-)).

    7. jyasskin commented on Mar 27, 2008

      jyasskinmannequin
      Mannequin

      I'll look at this tonight.

    8. self-assigned this
      on Mar 27, 2008
    9. jyasskin commented on Mar 28, 2008

      jyasskinmannequin
      Mannequin

      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.

    10. jyasskin commented on Mar 28, 2008

      jyasskinmannequin
      Mannequin

      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.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions