script uses up all memory

L

Larry Martell

I have a script that forks off other processes and attempts to manage
them. Here is a stripped down version of the script:

self.sleepTime = 300
self.procs = {}
self.startTimes = {}
self.cmd = ['python', '/usr/local/motor/motor/app/some_other_script.py']

while True:
try:
self.tools = Tool.objects.filter(ip__isnull=False)
except Exception, e:
print 'error from django call: ' + str(e)
sys.exit(1)

for tool in self.tools:
name = tool.name
if name in self.procs:
if self.procs[name].poll() is None:
if
(datetime.datetime.now()-self.startTimes[name]) >
datetime.timedelta(hours=12):
# it's been running too long - kill it
print 'killing script for ' + name + "
it's been running too long"
self.procs[name].kill()
else:
continue

if self.procs[name].returncode:
print 'scrikpt failed for ' + name + ', error
= ' + str(self.procs[name].returncode)

print 'starting script.py for ' + name + ' at ' +
str(datetime.datetime.now())
try:
self.procs[name] = subprocess.Popen(self.cmd)
self.startTimes[name] = datetime.datetime.now()
except Exception, e:
print 'error from Popen: ' + str(e)
sys.exit(1)
else:
print 'starting script.py for ' + name + ' at ' +
str(datetime.datetime.now())
try:
self.procs[name] = subprocess.Popen(self.cmd)
self.startTimes[name] = datetime.datetime.now()
except Exception, e:
print 'error from Popen: ' + str(e)
sys.exit(1)

time.sleep(self.sleepTime)


The script does what it's intended to do, however after about 2 hours
it has used up all the memory available and the machine hangs. Can
anyone see something that I am doing here that would be using memory
like this? Perhaps some immutable object needs to be repeatedly
recreated?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top