execfile question

Kerim Borchaev warkid at storm.ru
Wed Feb 20 05:42:35 EST 2002


Thanks to all who helped me to resolve this issue.
As I understand now dict passed as globals participates in a reference
circle which clear() nicely breaks.

Bengt Richter wrote:

> On Tue, 19 Feb 2002 16:23:19 +0300, Kerim Borchaev <warkid at storm.ru> wrote:
> 
>>Mark Barclay answered:
>>
>>> "del c" will cause your __del__() to be called.
>>yes
>>
>>> So will any other action that causes your instance to be garbage-collected.
>>I don't get it.
>>And can you explain who holds a reference on C instance in my example
>>when 'execfile' completes?
>>
> I suspect the anonymous directory you passed to execfile. Apparently
> dictionaries don't always get cleared automatically. I don't know
> if this is a bug. But if you do:
> 
> xdict = {}
> execfile('executable.py', xdict)
> xdict.clear()    # just del xdict doesn't do it
> 
> I think your example will give you what you expected.
> 
> Using default dicts like this:
> 
> execfile('executable.py')
> 
> works too.
> 
> Regards,
> Bengt Richter
> 
> 
>>Kerim.
>>
>>----------------------------------
>>My original question:
>>
>>> Can someone explain why while running this script I don't see C.__del__
>>> eventually called?
>>>
>>> For me the output of it's execution is:
>>>
>>> >main.py
>>> it's me
>>> init
>>> executed
>>> >
>>>
>>> ##main.py######################
>>> execfile('executable.py', {})
>>> print 'executed'
>>> ########################
>>>
>>> ##executable.py######################
>>> print "it's me"
>>> class C:
>>>     def __init__(self):
>>>         print 'init'
>>>     def __del__(self):
>>>         print 'deleted'
>>>
>>> c = C()
>>> ########################
>>>
>>> Thanks in advance.
>>
>>
>>
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list