[PEAK] memory leaks & stuff
alexander smishlajev
alex at ank-sia.com
Wed Sep 15 10:06:16 EDT 2004
Yaroslav Samchuk wrote, at 14.09.2004 20:52:
> On the last week we had discovered, that the application, which is
> developed by our team was leaking memory.
while hunting for this leak, i've got two questions:
- derived conditions Not, Intersect and Union are not exported from
events.sources. why?
- what's wrong with the following script?
=== cut ===
import gc
from peak.api import binding, events
from peak.running import commands, interfaces
class Ticker(binding.Component):
delay = 1
evt = binding.Make(events.Condition)
eventLoop = binding.Obtain(events.IEventLoop)
def _doEventLoop(self):
while True:
yield self.eventLoop.sleep(self.delay)
events.resume()
self.evt.set(True)
_doEventLoop = binding.Make(events.taskFactory(_doEventLoop),
uponAssembly=True)
class App(commands.AbstractCommand):
mainLoop = binding.Obtain(interfaces.IMainLoop)
def _doEventLoop(self):
while True:
yield self.evt; events.resume()
### non-leaking:
#self.evt.set(False)
### leaking:
self._delBinding("evt")
gc.collect()
print "Total objects:", len(gc.get_objects())
_doEventLoop = binding.Make(events.taskFactory(_doEventLoop),
uponAssembly=True)
evt = binding.Make(lambda self: Ticker(parentComponent=self,
delay=1).evt)
def _run(self):
return self.mainLoop.run()
if __name__ == "__main__":
commands.runMain(App)
=== cut ===
best wishes,
alex.
More information about the PEAK
mailing list