gc.garbage from paramiko
Neil Schemenauer
nas at arctrix.com
Thu Feb 9 15:47:40 GMT 2006
John A Meinel <john at arbash-meinel.com> wrote:
> You could move the close() into the member variable. And then
> main_obj.close() just calls the main_obj._secret_sauce.close().
That would be the right design, IMO. __del__ methods don't cause
problems if they are on objects that do not form a reference cycle.
Even if you very careful to ensure that your code does not create a
cycle involving your object, the user may create one.
A diagram:
A --> B --> B'
^ |
\ /
C<-
If B' contains the bits of B that need finalization then things work
fine. The GC will detect the cycle and clear the attributes of A,
B, and C. When that happens, B' __del__ will execute.
Using this design makes life easier for you and protects the user
(assuming they don't mess around with private attributes; in that
case they get what they deserve).
HTH,
Neil
More information about the bazaar
mailing list