Re: Unbound names in __del__

2005-06-18 Thread Torsten Bronger
Hallöchen! "Terry Reedy" <[EMAIL PROTECTED]> writes: > "Torsten Bronger" <[EMAIL PROTECTED]> wrote: > > [...] > >> 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. IIR

Re: Unbound names in __del__

2005-06-18 Thread Terry Reedy
"Torsten Bronger" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> 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 whol

Re: Unbound names in __del__

2005-06-18 Thread Peter Hansen
Torsten Bronger wrote: >>Torsten Bronger wrote: >>>keithley = GpibInstrument(14) >>>keithley.write("*IDN?") >>>print keithley.read() >> [on using atexit] > However, this doesn't close sessions while the program is running. > If the programmer has the above code in a function which is ca

Re: Unbound names in __del__

2005-06-18 Thread Dieter Maurer
Peter Hansen <[EMAIL PROTECTED]> writes on Fri, 17 Jun 2005 08:43:26 -0400: > ... > And I don't recall the last time I saw a __del__ in third-party code I > was examining. > > > What's your use case for del? I had to use one a few days ago: To call the "unlink" method of a "minidom" object

Re: Unbound names in __del__

2005-06-18 Thread Torsten Bronger
Hallöchen! Peter Hansen <[EMAIL PROTECTED]> writes: > 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 progra

Re: Unbound names in __del__

2005-06-18 Thread Peter Hansen
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 issu

Re: Unbound names in __del__

2005-06-18 Thread Torsten Bronger
Hallöchen! Peter Hansen <[EMAIL PROTECTED]> writes: > Torsten Bronger wrote: > >> Peter Hansen <[EMAIL PROTECTED]> writes: >> >>> What's your use case for del? >> >> Every instance represents a "session" to a measurement instrument. >> After the instance is deleted, the session should be closed t

Re: Unbound names in __del__

2005-06-18 Thread Peter Hansen
Torsten Bronger wrote: > Peter Hansen <[EMAIL PROTECTED]> writes: >>What's your use case for del? > > Every instance represents a "session" to a measurement instrument. > After the instance is deleted, the session should be closed to free > resources. You mean like GPIB devices? We've written a

Re: Unbound names in __del__

2005-06-17 Thread Torsten Bronger
Hallöchen! Peter Hansen <[EMAIL PROTECTED]> writes: > [...] > > What's your use case for del? Every instance represents a "session" to a measurement instrument. After the instance is deleted, the session should be closed to free resources. If the program exists, this is actually not necessary,

Re: Unbound names in __del__

2005-06-17 Thread Peter Hansen
Torsten Bronger wrote: > However, all of this is not pretty pythonic in my opinion. Is it > that exotic to want to call functions from within __del__? Yes, I think it probably is. In the few hundred thousand lines of Python code I've played a role in developing, we've used __del__ once, to my

Re: Unbound names in __del__

2005-06-17 Thread Michael Hoffman
Torsten Bronger wrote: > When my __del__ methods are called because the program is being > terminated, I experience difficulties in calling functions that I > need for a clean shutdown of my instances. So far, there has been > only one of these functions, and a class-local alias solved the > prob

Re: Unbound names in __del__

2005-06-17 Thread Torsten Bronger
Hallöchen! "Terry Reedy" <[EMAIL PROTECTED]> writes: > "Torsten Bronger" <[EMAIL PROTECTED]> wrote: > >> Is there a way to detect whether the program is being terminated? > > See atexit module to register cleanup functions that run *before* > the interpreter starts haphazardly deleting stuff. So

Re: Unbound names in __del__

2005-06-16 Thread Terry Reedy
"Torsten Bronger" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >Is there a way to detect whether the program is being terminated? See atexit module to register cleanup functions that run *before* the interpreter starts haphazardly deleting stuff. Terry J. Reedy -- http://ma

Unbound names in __del__

2005-06-16 Thread Torsten Bronger
Hallöchen! When my __del__ methods are called because the program is being terminated, I experience difficulties in calling functions that I need for a clean shutdown of my instances. So far, there has been only one of these functions, and a class-local alias solved the problem. However, now the