durusmail: quixote-users: Re: Request contexts
Request contexts
2003-12-11
Re: Request contexts
2003-12-11
2003-12-11
2003-12-12
2003-12-12
2003-12-13
2003-12-13
2003-12-16
2003-12-16
2003-12-16
2003-12-16
2003-12-15
Re: Request contexts
2003-12-16
2003-12-16
2003-12-24
2003-12-30
2003-12-31
Re: Request contexts
Skip Montanaro
2003-12-16
    >> And, my clean-up code works, too.  The __del__ method in MyPublisher
    >> (my subclass of Publisher) is called whenever I restart or stop the
    >> SCGI server.  Cool.

    Matt> Hmm, I wouldn't rely on __del__ methods to clean up resources. For
    Matt> a start, it's up to the garbage collector when they get called but
    Matt> more importantly , there's no guarantee that __del__ actually
    Matt> *will* get called. I understand __del__ can also cause problems in
    Matt> circular dependencies but I can't remember what the problem is
    Matt> now.

There's no problem with using __del__ to clean things up as long as the
object containing __del__ isn't involved in any cycles.  In that situation,
the object's reference count will drop to zero, its __del__ method will get
called, then any remaining resources will be reclaimed.  __del__ causes
problems with circular dependencies because the cyclic garbage collector
can't tell what object's reference count to decrement first.  If it picks
wrong, a __del__ method might get executed after something it relies on gets
cleaned up.  If the cyclic garbage collector discovers objects in a cycle
with __del__ methods, it just hangs the whole thing off of gc.garbage.

Neil Schemenauer's essay about the cyclic garbage collector (he was the
primary author) is still useful reading, even though it's three years old:

    http://arctrix.com/nas/python/gc/

Skip


reply