[Scipy-tickets] [SciPy] #1501: import in member function causes object to persist

SciPy Trac scipy-tickets@scipy....
Tue Aug 23 12:44:37 CDT 2011


#1501: import in member function causes object to persist
----------------------------------------+-----------------------------------
 Reporter:  gertjan                     |       Owner:  somebody   
     Type:  defect                      |      Status:  new        
 Priority:  normal                      |   Milestone:  Unscheduled
Component:  Other                       |     Version:  0.8.0      
 Keywords:  import, garbage collection  |  
----------------------------------------+-----------------------------------

Comment(by rgommers):

 I can reproduce this with scipy, not with numpy or anything else.  Running
 the same script within ipython instead of with plain python shows the
 {{{__del__}}} method is called immediately. This makes it unlikely that
 this is something in scipy itself. If it is though, it must be the
 PackageLoader stuff in the {{{__init__.py}}} files - that will be removed
 very soon.

 My guess is you're just looking at peculiarities of the del and import
 implementation in Python. The warnings at
 http://docs.python.org/reference/datamodel.html?highlight=__del__#object.__del__
 show that this is a messy business.

 Question: why do you do this in the first place? The name scipy is not
 available anywhere except in your {{{__init__}}} method.  This will give a
 NameError:
 {{{
 class A:
   def __init__( self ):
     import scipy
   def __del__( self ):
     print scipy.__version__
     print 'DELETED'


 a = A()
 del a
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1501#comment:3>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list