Changes between Initial Version and Version 1 of Ticket #40, comment 4


Ignore:
Timestamp:
01/05/16 14:59:32 (9 years ago)
Author:
zhangjr
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #40, comment 4

    initial v1  
    1 Another possible solution.
     1Another possible solution. weakref+with
    22
    33===
     
    99        self.parent = weakref.ref(parent)
    1010        #self.parent =parent
    11         print 'Foo', self.id, 'born'
     11        print 'child', self.id, 'new'
    1212
    1313    def __del__(self):
    14         print 'Foo', self.id, 'died'
     14        print 'child', self.id, 'del'
     15
     16    def __exit__(self, type, value, traceback):
     17        print 'child', self.id, 'exit'
     18
     19    def __enter__(self):
     20        print 'child', self.id, 'enter'
    1521
    1622
     
    1824    def __init__(self, id):
    1925        self.id = id
    20         self.foo = FooType(id, self)
    21         print 'Bar', self.id, 'born'
     26        print 'main', self.id, 'new'
     27        with  FooType(id, self) as self.foo:
     28            pass
    2229
    2330    def __del__(self):
    24         print 'Bar', self.id, 'died'
     31        print 'main', self.id, 'del'
    2532
    2633b = BarType(12)