[PEAK] memory leaks & stuff

Phillip J. Eby pje at telecommunity.com
Tue Sep 14 14:13:30 EDT 2004

At 08:52 PM 9/14/04 +0300, Yaroslav Samchuk wrote:
>peak.events.loop[1396]:     callbacks.pop(0)[0](self,event)
>peak.events.loop[1396]:   File 
>"E:\Python23\Lib\site-packages\peak\events\sources.py", line 107, in cb
>peak.events.loop[1396]:     return f(cbr(),src,evt)
>peak.events.loop[1396]:   File 
>"E:\Python23\Lib\site-packages\peak\events\sources.py", line 518, in _set
>peak.events.loop[1396]:     self._fire(evt)
>peak.events.loop[1396]: AttributeError: 'NoneType' object has no attribute 

I see what might be causing this problem; there may be a race condition 
here, if the callback is invoked when the weak reference is dead, but 
hasn't called its cleanup routines yet.  (How this can happen exactly, I 
don't know).  But I can fix this, by changing the two 'def cb()' functions 
to check that 'cbr() is not None' before proceeding with their method bodies.

>peak.events.loop[1224]:     fr,fw,fe = 
>peak.events.loop[1224]: error: (10038, 'An operation was attempted on 
>something that is not a socket')
>Traceback (most recent call last):
>StopIteration: Nothing scheduled to execute
>gc: collectable <Broadcaster 00BD9E18>
>gc: collectable <tuple 00BDB3F0>
>and I can't get rid of this exception - socket should be closed to that
>moment, events should be destroyed (I hope so - I call
>`self._delBinding` to loose references to event objects).

I suspect this is related to the same issue that Vladimir Iliev was 
having.  Specifically, that I/O events aren't smart enough to know when 
they're really being used.  They should only be passed to the select() when 
they have active callbacks.

I don't know whether any of these things relate to your memory leak.  At 
one time, I had discovered that 'events.AnyOf' had a memory leak, but I'm 
pretty sure it got fixed.  That doesn't preclude the possibility of others, 
though, as event systems are pretty hard to do correctly without creating 
circular references of some kind.

More information about the PEAK mailing list