Unbound names in __del__

Terry Reedy tjreedy at udel.edu
Sat Jun 18 18:27:44 EDT 2005


"Torsten Bronger" <bronger at physik.rwth-aachen.de> wrote in message 
news:87is0bmvqt.fsf at wilson.rwth-aachen.de...
>> Torsten Bronger wrote:
>>
>>>     keithley = GpibInstrument(14)
>>>     keithley.write("*IDN?")
>>>     print keithley.read()

>>> A keithley.close() would be a wart in my opinion; instead I want
>>> to hide the whole session thing from the programmer.  Besides, I
>>> haven't yet given up the hope that the issues with __del__ can be
>>> tackled.

> However, this doesn't close sessions while the program is running.
> If the programmer has the above code in a function which is called
> repeatedly, he may run into trouble.  IIRC my current VISA DLL has
> only 256 session slots.

Deleting during a run is a different issue from deleting during program 
shutdown, which is where you started us.  In CPython, 'del keithley' will, 
if keithley is the last reference to the object, dependably delete and 
object, calling __del__ on the way.  For other implementations, deleting 
the last reference makes the object eligible to be deleted 'sometime' (if 
and when garbage collection happens).  So an explicit close is the only 
dependable cross-implementation method that I know of.

Terry J. Reedy






More information about the Python-list mailing list