You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test_no_refcycle_through_target sometimes fails in test_threading #46748
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=Noneclosed_at=<Date2008-03-28.04:12:52.791>created_at=<Date2008-03-27.12:04:29.607>labels= ['type-bug', 'library']
title='test_no_refcycle_through_target sometimes fails in test_threading'updated_at=<Date2008-03-28.04:12:52.789>user='https://github.com/pitrou'
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().
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
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.
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 commented on Mar 28, 2008
jyasskinmannequin
Mannequin
More actions
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.
Activity
pitrou commentedon 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 commentedon 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:
references to local variables, preventing them to be deallocated
pitrou commentedon Mar 27, 2008
Hmm, even with a Py_DEBUG build I can't reproduce the bug.
pitrou commentedon 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 commentedon 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 commentedon Mar 27, 2008
I'll look at this tonight.
jyasskin commentedon 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 commentedon 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.