On Mon, Jun 14, 2010 at 7:33 AM, Michael Goldish <[email protected]>wrote:

> On 06/14/2010 05:08 PM, John Admanski wrote:
> > Note that if gc.collect is needed to collect garbage, that generally
> > means you have reference cycles, and if you have __del__ AND cycles then
> > even a gc.collect won't help you. A __del__ method will prevent the
> > proper collection of objects involved in a reference cycle.
> >
> > -- John
>
> It isn't needed AFAIK, and I don't think I have any reference cycles.  I
> did make sure that after applying the patch, my __del__ method is
> properly called before test termination, even without gc.collect().  The
> only reason I put gc.collect() there is that I'm not sure about python's
> garbage collection policy -- is garbage collection guaranteed to take
> place as soon as the reference count drops to zero?  or does it perhaps
> depend on a clean exit?  I thought it was slightly risky to rely on
> garbage collection immediately before an os._exit().  Please correct me
> if I'm wrong.
>
>
Well, in practice the reference count dropping to zero will trigger an
immediate collection of an object. I just wanted to point out that if the
problem was the objects with __del__ were not getting cleaned up, then the
gc.collect doesn't really help since objects that need the cyclic collector
won't get cleaned up anyway if they have a __del__.

-- John


> >
> > On Sat, Jun 12, 2010 at 3:20 PM, Michael Goldish <[email protected]
> > <mailto:[email protected]>> wrote:
> >
> >     If an exception is raised in a test, its traceback contains
> >     references to
> >     objects used in the test.  These references prevent garbage
> >     collection of the
> >     objects.  Normally this isn't a problem because when a program exits
> the
> >     objects are garbage-collected anyway, but fork_start() calls
> >     os._exit() which
> >     skips normal exit processing.  Thus we can't rely on objects'
> >     __del__() methods
> >     being called.
> >
> >     The problem can be solved by calling sys.exc_clear() to clear
> exception
> >     information before exiting.  It also doesn't hurt to call
> >     gc.collect() just to
> >     be very sure that garbage collection takes place.
> >
> >     Signed-off-by: Michael Goldish <[email protected]
> >     <mailto:[email protected]>>
> >     ---
> >      client/bin/parallel.py |    6 +++++-
> >      1 files changed, 5 insertions(+), 1 deletions(-)
> >
> >     diff --git a/client/bin/parallel.py b/client/bin/parallel.py
> >     index 1ecc75f..47dd5cd 100644
> >     --- a/client/bin/parallel.py
> >     +++ b/client/bin/parallel.py
> >     @@ -2,7 +2,7 @@
> >
> >      __author__ = """Copyright Andy Whitcroft 2006"""
> >
> >     -import sys, logging, os, pickle, traceback
> >     +import sys, logging, os, pickle, traceback, gc
> >      from autotest_lib.client.common_lib import error, utils
> >
> >      def fork_start(tmp, l):
> >     @@ -39,6 +39,10 @@ def fork_start(tmp, l):
> >                     sys.stdout.flush()
> >                     sys.stderr.flush()
> >             finally:
> >     +            # clear exception information to allow garbage
> >     collection of
> >     +            # objects referenced by the exception's traceback
> >     +            sys.exc_clear()
> >     +            gc.collect()
> >                 os._exit(1)
> >         else:
> >             try:
> >     --
> >     1.5.4.1
> >
> >     _______________________________________________
> >     Autotest mailing list
> >     [email protected] <mailto:[email protected]>
> >     http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
> >
> >
>
>
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to