[BangPypers] Simulating atexit using weakref (was How to run a block of code just before the interpreter is being exited ...)
Anand Chitipothu
anandology at gmail.com
Tue Sep 10 08:38:05 CEST 2013
On Tue, Sep 10, 2013 at 11:43 AM, Anand B Pillai <
anandpillai at letterboxes.org> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Tuesday 10 September 2013 11:30 AM, Anand B Pillai wrote:
>
> > Don't advise anyone to use this code - it is just to illustrate
> > the one of the ways in which weak references can be used. In
> > general it is better not to rely on the order of gc in your code
> > to implement a feature.
>
> Here is the code in pastebin - http://pastebin.com/wmLduVBh
You can also achieve the same using __del__.
class Foo:
def __del__(self):
print "on exit"
foo = Foo()
if __name__ == '__main__':
print 3+4
print 8+9
More information about the BangPypers
mailing list