Edgewall Software

Ticket #1401: trac-svn-pool-children-#1401.patch

File trac-svn-pool-children-#1401.patch, 2.8 KB (added by mrowe, 4 years ago)

Patch against source:/trunk#1544 to have a Pool wait until it's children have been closed to close itself.

  • trac/versioncontrol/svn_fs.py

    === trac/versioncontrol/svn_fs.py
    ==================================================================
     
    6161    Instances of this type return their associated `pool when called. 
    6262    """ 
    6363     
    64     def __init__(self, parent, parent_pool=lambda: None): 
     64    def __init__(self, parent, parent_pool=None): 
    6565        """ 
    6666        Create a new pool that is a sub-pool of `parent_pool`, and arrange for 
    67         `self.close` to be called up when the `parent` object is destroyed. 
     67        `self._close` to be called up when the `parent` object is destroyed. 
    6868         
    6969        The `parent` object must be weak-referenceable.  The returned `Pool` 
    7070        instance will have the value of the newly created pool.  
    7171        """ 
    72         self.pool = core.svn_pool_create(parent_pool()) 
    73         self.children = [] 
     72        self._parent_pool = parent_pool 
     73        self._children = [] 
     74        self._waiting_to_close = False 
    7475         
    75         if parent_pool(): 
    76             parent_pool.children.append(self) 
     76        if self._parent_pool: 
     77            self._pool = core.svn_pool_create(self._parent_pool())         
     78            self._parent_pool._children.append(self) 
     79        else: 
     80            self._pool = core.svn_pool_create(None) 
    7781         
    7882        try: 
    79             parent._pool_closer = weakref.ref(parent, self.close) 
     83            parent._pool_closer = weakref.ref(parent, self._close) 
    8084        except TypeError: 
    81             self.close(None) 
     85            self._close(None) 
    8286            raise 
    8387     
    8488    def __call__(self): 
    85         return self.pool 
     89        return self._pool 
    8690     
    87     def close(self, x): 
     91    def _child_closed(self, child): 
     92        self._children.remove(child) 
     93        if self._waiting_to_close: 
     94            self._close(x) 
     95     
     96    def _close(self, x): 
    8897        """ 
    8998        The parent object has been destroyed so it is time for us to go. 
    9099         
     100        If we still have children that are alive, we do not clean up just 
     101        yet.  This would lead to their memory being freed from under them. 
     102        Instead, we wait for our child to notify us that they have been 
     103        closed and clean up then.  
     104         
    91105        -- So long, and thanks for all the fish! 
    92106        """ 
    93         if not self.pool: 
     107        assert self._pool 
     108         
     109        if self._children: 
     110            self._waiting_to_close = True 
    94111            return 
    95112         
    96         while self.children: 
    97             self.children.pop().close(None) 
     113        core.svn_pool_destroy(self._pool) 
     114        self._pool = None 
    98115         
    99         core.svn_pool_destroy(self.pool) 
    100         self.pool = None 
     116        if self._parent_pool: 
     117            self._parent_pool._child_closed(self) 
     118            self._parent_pool = None 
    101119 
    102120 
    103121class SubversionRepository(Repository):