On 31 jan, 01:03, Larry Bates <larry.ba...@websafe.comwrote:
TimD...@gmail.com wrote:
Hello,
I'm writing a python script for Amarok, I communicate with Amarok
using DCOP.
Now, I have to call DCOP very often and I noticed that every time I
make a DCOP call my program keeps growing in memory size.
To make sure it was DCOP i wrote the small program below:
from dcopext import DCOPClient, DCOPApp
while 0==0:
dcop=DCOPClient()
dcop.attach()
AmarokDcopRes = DCOPApp ("amarok", dcop)
ok, Ms = AmarokDcopRes.player.trackCurrentTimeMs()
print Ms
If you run this script and monitor it's memory use you'll see that it
keeps growing.
Does anyone know how I can solve this problem?
Kind regards,
Tim
I think you will find the objects are getting created so fast that
garbage collection doesn't have time to clean them up as fast
as you are creating new ones. Since del dcop is not guaranteed
to be "immediate" that won't help.
Q: Can't you create dcop instance outside the loop and reuse it
for every time through the loop?
Q: Can you sleep or something after each loop or do you really
want to peg the CPU checking forever?
Q: How do you ever get out of this infinite loop?
Note: while 0=0 is better written as while 1: and you need a
break somewhere to get out of the loop.
-Larry
Hi,
Thanks for the quick response.
The code I posted is not my actual program and was only to demonstrate
my problem. The complete program I'm writing uses QT and so the loop
is replaced by a Timer event.
I tried out the suggestion. I had already tried the del dcop
instruction, so I knew that wasn't it. I also placed the DCOP variable
outside my loop but that didn't help either.
What I did notice that my program only grew in memory use when the
'ok, Ms = AmarokDcopRes.player.trackCurrentTimeMs() ' code was
executed (or any other function using the AmarokDcopRes variable like
'ok, volume = AmarokDcopRes.player.getVolume()' )
Then I also tried to make my take a pause of a second in the loop but
this also didn't help, the program was still growing in memory use (a
lot slower though but I don't call that a solution)
So if you have any more ideas let me know. I'll keep on trying
Kind regards,
Tim