Confusion with weakref, __del__ and threading
rhamph at gmail.com
Wed Jun 11 20:37:45 EDT 2008
On Jun 11, 2:15 pm, George Sakkis <george.sak... at gmail.com> wrote:
> On Jun 11, 2:01 pm, Rhamphoryncus <rha... at gmail.com> wrote:
> > On Jun 11, 10:43 am, George Sakkis <george.sak... at gmail.com> wrote:
> > > On Jun 11, 1:40 am, Rhamphoryncus <rha... at gmail.com> wrote:
> > > > The trick here is that calling proxy.sleep(0.01) first gets a strong
> > > > reference to the Mystery instance, then holds that strong reference
> > > > until it returns.
> > > Ah, that was the missing part; I thought that anything accessed
> > > through a proxy didn't create a strong reference. The good thing is
> > > that it seems you can get a proxy to a bounded method and then call it
> > > without creating a strong reference to 'self':
> > That's not right. Of course a bound method has a strong reference to
> > self, otherwise you'd never be able to call it. There must be
> > something else going on here. Try using sys.setcheckinterval(1) to
> > make threads switch more often.
> I tried that and it still works; all objects die at the main thread.
> Any other idea to break it ?
Nothing comes to mind.
However, none of this is guaranteed anyway, so you can't rely on it.
__del__ might be called by any thread at any point (even when you're
holding a lock, updating a datastructure.)
More information about the Python-list