Re: Cleaning up after failing to contructing objects

2009-07-15 Thread Shai
Since nobody else mentioned this... Python classes have a magic method called __del__ which is usually called just before an object is garbage-collected. Further, Python uses reference-counting to tell when an object is no longer accessible. This means that if your resource classes define __del__

Re: Cleaning up after failing to contructing objects

2009-07-09 Thread Mattias Brändström
On Jul 9, 7:30 pm, Lie Ryan wrote: > brasse wrote: > > Hello! > > I have been thinking about how write exception safe constructors in > > Python. By exception safe I mean a constructor that does not leak > > resources when an exception is raised within it. The following is an > > example of one po

Re: Cleaning up after failing to contructing objects

2009-07-09 Thread Lie Ryan
brasse wrote: > Hello! > I have been thinking about how write exception safe constructors in > Python. By exception safe I mean a constructor that does not leak > resources when an exception is raised within it. The following is an > example of one possible way to do it: First, your automatic clea

Re: Cleaning up after failing to contructing objects

2009-07-08 Thread Mattias Brändström
On Jul 6, 11:15 pm, Scott David Daniels wrote: > brasse wrote: > > I have been thinking about how write exception safe constructors in > > Python. By exception safe I mean a constructor that does not leak > > resources when an exception is raised within it. > > ... >  > As you can see this is less

Re: Cleaning up after failing to contructing objects

2009-07-06 Thread Gabriel Genellina
En Mon, 06 Jul 2009 18:15:44 -0300, Scott David Daniels escribió: brasse wrote: I have been thinking about how write exception safe constructors in Python. By exception safe I mean a constructor that does not leak resources when an exception is raised within it. ... > As you can see this i

Re: Cleaning up after failing to contructing objects

2009-07-06 Thread Scott David Daniels
brasse wrote: I have been thinking about how write exception safe constructors in Python. By exception safe I mean a constructor that does not leak resources when an exception is raised within it. ... > As you can see this is less than straight forward. Is there some kind > of best practice tha

Cleaning up after failing to contructing objects

2009-07-06 Thread brasse
Hello! I have been thinking about how write exception safe constructors in Python. By exception safe I mean a constructor that does not leak resources when an exception is raised within it. The following is an example of one possible way to do it: class Foo(object): def __init__(self, name, f