Changeset 1580:91f6455e19e4

Show
Ignore:
Timestamp:
10/28/08 12:57:39 (2 months ago)
Author:
Dan Blankenberg <dan@bx.psu.edu>
branch:
default
Message:

Use a weakref in metadata to prevent a circular reference possibly interfering with garbage collection: hda/lda (parent) <--> MetadataCollection? (self)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/galaxy/datatypes/metadata.py

    r1568 r1580  
    1 import sys, logging, copy, shutil 
     1import sys, logging, copy, shutil, weakref 
    22 
    33from galaxy.util import string_as_bool 
     
    4141        if self.parent._metadata is None: 
    4242            self.parent._metadata = {} 
     43    def get_parent( self ): 
     44        if "_parent" in self.__dict__: 
     45            return self.__dict__["_parent"]() 
     46        return None 
     47    def set_parent( self, parent ): 
     48        self.__dict__["_parent"] = weakref.ref( parent ) # use weakref to prevent a circular reference interfering with garbage collection: hda/lda (parent) <--> MetadataCollection (self) ; needs to be hashable, so cannot use proxy. 
     49    parent = property( get_parent, set_parent ) 
    4350    @property 
    4451    def spec( self ): 
     
    6673    def __setattr__( self, name, value ): 
    6774        if name == "parent": 
    68             self.__dict__[name] = value 
     75            return self.set_parent( value ) 
    6976        else: 
    7077            if name in self.spec: