Changeset 239

Show
Ignore:
Timestamp:
Mon Feb 6 05:42:44 2006
Author:
giovannibajo
Message:

Fix ticket #32*: mimic Python 2.4 cleanup behaviour with broken modules

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/iu.py

    r203 r239  
    29 29 import marshal  
    30 30  
      31 try:  
      32     py_version = sys.version_info  
      33 except AttributeError:  
      34     py_version = (1,5)  
      35  
    31 36 #=======================Owners==========================#  
    32 37 # An Owner does imports from a particular piece of turf  
     
    387 392                 co = mod.__co__  
    388 393                 del mod.__co__  
    389                   if reload:  
    390                       exec co in sys.modules[fqname].__dict__  
    391                   else:  
    392                       exec co in mod.__dict__  
      394                 try:  
      395                     if reload:  
      396                         exec co in sys.modules[fqname].__dict__  
      397                     else:  
      398                         exec co in mod.__dict__  
      399                 except:  
      400                     # In Python 2.4 and above, sys.modules is left clean  
      401                     # after a broken import. We need to do the same to  
      402                     # achieve perfect compatibility (see ticket #32).  
      403                     if py_version >= (2,4,0):  
      404                         # FIXME: how can we recover from a broken reload()?  
      405                         # Should we save the mod dict and restore it in case  
      406                         # of failure?  
      407                         if not reload:  
      408                             del sys.modules[fqname]  
      409                     raise  
    393 410             if fqname == 'thread' and not self.threaded:  
    394 411 ##                print "thread detected!"