title: How to wait for destruction of Python object
body: <p>Is there a way to tell when the destructor of an object has been called by the garbage collector? I need to know this because of some network resources I need right after a destructor frees them. For example, the destructor deletes a virtual network interface that might be added again right away. This of course leads to problems when the interface is re-added before it is deleted by the destructor. The necessary resource frees happen in the <code>__del__(self)</code> function of the object representing the virtual network.</p>
  
  <pre><code>def __del__(self):
          print("Deconstructing " + self.devName)
             [...]
          sub.call(["ip", "link", "delete", self.devName])
          sub.call(["pkill", "dnsmasq"])
          try:
              os.remove("/var/lib/misc/dnsmasq.leases")
          except:
              "No dhcp leases to delete"
  </code></pre>