termios disappears during object deletion

Hans Nowak hnowak at cuci.nl
Sat Sep 4 04:09:10 EDT 1999


On 3 Sep 99, at 22:58, Brien Barton wrote:

> Can anyone explain this behavior??  For some reason, the termios and
> TERMIOS modules get wiped out when python is running the __del__ method
> during program termination.  I've tried this with Python 1.5.1 on Linux
> and with Python 1.5.2 on SGI IRIX.  If you explicitly delete the object,
> you don't have this problem.
> 
> ~> cat test.py
> import math, termios, TERMIOS
> 
> print 'math=', math
> print 'termios=', termios
> print 'TERMIOS=', TERMIOS
> 
> class Test:
>     def __del__(self):
>         print 'deleting Test object ...'
>         print 'math=', math
>         print 'termios=', termios
>         print 'TERMIOS=', TERMIOS
> 
> t = Test()

I'm not sure, but I have a vague idea why this happens... an instance 
of Test is created, then the program is finished. Python starts 
cleaning up some stuff, freeing memory, etc. *Maybe* (as said, I 
don't know this fer shure) it first gets rid of termios and TERMIOS, 
then it takes on the Test instance t, calling its __del__ method. 
This method then correctly sees that termios and TERMIOS are already 
deleted.

Just an idea... I don't know much about Python's internals, but it 
would make sense to me...

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://fly.to/zephyrfalcon
Python Snippets: http://www.hvision.nl/~ivnowa/snippets/
The Purple Kookaburra Forum: http://www.delphi.com/kookaburra/




More information about the Python-list mailing list