Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'none:': 0.07; 'exception,': 0.09; 'immutable': 0.09; 'subject:script': 0.09; 'try:': 0.09; 'django': 0.11; 'long"': 0.16; 'self.cmd': 0.16; 'sys.exit(1)': 0.16; 'true:': 0.16; 'do,': 0.16; 'machine': 0.22; 'memory': 0.22; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'this?': 0.23; 'error': 0.23; 'script': 0.25; 'skip:( 40': 0.30; 'message-id:@mail.gmail.com': 0.30; 'anyone': 0.31; 'subject:all': 0.32; 'running': 0.33; 'skip:d 20': 0.34; 'except': 0.35; 'skip:s 30': 0.35; 'tool': 0.35; 'something': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'doing': 0.36; 'too': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:t 30': 0.61; 'name': 0.63; 'hours': 0.66; 'here': 0.66; 'forks': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=OcJrt0qbNUdN/Or3q6XIumHny0L4k/c9x1uEjuyBIls=; b=cYkvfuXYsGUk4rSBV8yxYI7IeskG9OqEd8wZdiXqOlVq5/sZNEqRPyMIkqS82W6aJZ Q21iHoOgjq8OcJJe5zbuGbHGktRF42+If+WCuAOPVubKq8Prz+as8LcHjZqFqDjaqvhH 4LPfAfNdL0sI7N4YPYdtcN7Rvw3SHvTu/niv3ojdwzzONH6y5QQ/YfMBo3UBAI3Mo6dq d9u4pnN4f8bT/aKcgJE3rMfmslg19BSAvkIKKQO93812So+BfzrEMiHTBfG06qViayL7 bU37sS0K2tBcL5tNSbDowNUj2sGf61/rqjwOEa94QbGEPDODMFjUpyYIgC9S7swfq5p4 J4CQ== MIME-Version: 1.0 X-Received: by 10.194.60.37 with SMTP id e5mr4744741wjr.32.1394058451227; Wed, 05 Mar 2014 14:27:31 -0800 (PST) Date: Wed, 5 Mar 2014 17:27:31 -0500 Subject: script uses up all memory From: Larry Martell To: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1394058453 news.xs4all.nl 2939 [2001:888:2000:d::a6]:34783 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:67891 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?