This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Kross-python script eats memory (script to log data)

Tags: None
(comma "," separated)
Rioting_Pacifist
Registered Member
Posts
27
Karma
0
Addon to log data hemorages memory.

I think it may be related to an old kross-python bug, but could somebody double check it isn't my code that is leaking

it should fire a timer every 1000ms and then log the result of some stats lookups and a ping to a file.
and it does do this but it also makes ktorrent eat up memory that is never released

Code: Select all
#!/usr/bin/env kross
# -*- coding: utf-8 -*-
# Author=Juan Canham
# Email=Juan_dot_Canham at googlemail_dot_com
# Website=npme
# License=GPL
# Script repository=none
# ScriptName = "logger.py"
# Last Edit Date : 27/3/2011
#
# just logging some data to see when my ISP throttles or conenction is screwed

import KTorrent
import Kross
import KTScriptingPlugin
from subprocess import Popen, PIPE
from time import time, sleep

tors = KTorrent.torrents()
log = open('/tmp/log',"w")

def unload():
  loaded = False
  log.close()


class mainClass:
  def __init__(self):
    self.wait = 1000
    self.timer = KTScriptingPlugin.createTimer(True)
    self.timer.connect('timeout()',self.outputData)

  def outputData(self):
    if loaded:
      stime = time()
      upload = download = bandwidth = seeders = leechers = connections = 0
      for torName in KTorrent.torrents():
   tor = KTorrent.torrent(torName)
   upload += tor.uploadSpeed()
   download += tor.downloadSpeed()
   leechers += tor.leechersConnected()
   seeders += tor.seedersConnected()
   
      bandwidth = upload + download
      connections = leechers + seeders

      stout = Popen(['ping','-q','-c 1','74.125.230.114'], stdout=PIPE).communicate()[0]
      ping = stout.split()[-2].split('/')[0]
      dtime = time() - stime

      datastr = str(stime)+','+str(dtime)+','+str(ping)+','+str(upload)+','+str(download)+','+str(bandwidth)+','+str(leechers)+','+str(seeders)+','+str(connections)
      log.write(datastr+'\n')
      log.flush()
      self.timer.start(self.wait)


loaded = True
mc = mainClass()
mc.outputData()
George
Moderator
Posts
5421
Karma
1
Check that the child processes you spawn with Popen are cleaned up, and they don't stay alive as zombies.
Rioting_Pacifist
Registered Member
Posts
27
Karma
0
Sorry for the long delay, I've been quite busy with other stuff but i can confirm that there are no left over pings

It eats up memory at a significant rate (here it is after ~8 minutes)
Code: Select all
 PID TTY        S     TIME  MAJFL   TRS   DRS      RSS     %MEM COMMAN
 8147 pts/6    Dl     3:15    284     855   795612 172908  8.6      ktorrent
 8147 pts/6    Sl     4:44    364     855   879388 238468 11.9      ktorrent

DRS = + 83776 = 81MiB
RRS = + 65560 = 65MiB
Total = + 146MiB
vs background ktorrent
Code: Select all
 9548 pts/6    Sl     0:05      3    855 738832 64428  3.2 ktorrent
 9548 pts/6    Rl     1:39     74   855 719144 121172  6.0 ktorrent

DRS = - 19688 = -19MiB
RRS = + 56744 = +55MiB
Total = + 36MiB

While the conditions are not identical it's a difference of over 100MiB in 8 minutes, making all my scripts unusable

I think the bug is https://bugs.kde.org/show_bug.cgi?id=203922 based on last time i tried using kross

Ktorrent Version 4.0.5
Using KDE Development Platform 4.6.2 (4.6.2)
from kubuntu ppa
Architecture: amd64
Version: 4.0.5-3ubuntu1~maverick1~ppa1

which krosspython from
Architecture: amd64
Source: kdebindings
Version: 4:4.5.90-0ubuntu1~maverick1~ppa3
George
Moderator
Posts
5421
Karma
1
Krosspython appears to be not very actively maintained, it's most likely something similar like the already known memory leak.

Maybe it's time, I converted the existing scripts to ruby or javascript.


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Google [Bot], Sogou [Bot]