Note that there are some explanatory texts on larger screens.

plurals
  1. POpython: what prevents from object destroy?
    primarykey
    data
    text
    <p>If you define a class instance in a function, when the function exits, the instance will be automatically destroyed due to out of scope. This can be simply verified by a small program:</p> <pre><code>class A(object): def __del__(self): print 'deleting A ', id(self) class B(A): def __init__(self): self.a = A() def __del__(self): print 'deleting B ', id(self) super(B, self).__del__() def test(): b = B() print 'this is ', b test() </code></pre> <p>The output is:</p> <pre><code>this is &lt;__main__.B object at 0x01BC6150&gt; deleting B 29122896 deleting A 29122896 deleting A 29122960 </code></pre> <p>But I'm encountering a weird problem. When I inherit a class from novaclient, the instance will never be automatically destroyed.</p> <pre><code>from novaclient.v1_1.client import Client as NovaClient class ViviNovaClient(NovaClient): def __init__(self, auth_token, url, tenant_id): super(ViviNovaClient, self).__init__(None, None, tenant_id, auth_url = 'http') self.client.management_url = url self.client.auth_token = auth_token self.client.used_keyring = True; LOG.info('creating &lt;ViviNovaClient&gt; %d' % id(self)) def __del__(self): LOG.info('deleting &lt;ViviNovaClient&gt; %d' % id(self)) if __name__ == '__main__': def test(): client = ViviNovaClient('53ef4c407fed45de915681a2d6aef1ee', 'http://135.251.237.130:8774/v2/082d8fd857f44031858827d149065d9f', '082d8fd857f44031858827d149065d9f') test() </code></pre> <p>Output is:</p> <pre><code>2013-05-24 23:08:03 32240 INFO vivi.vivimain.ViviNovaClient [-] creating &lt;ViviNovaClient&gt; 26684304 </code></pre> <p>In this test, 'client' object is not destroyed. So I wonder what will prevent the 'client' object from auto destroying?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload