Re: [Pyunit-interest] PyUnitTestBrowser - Memory leak
Brought to you by:
purcell
From: Alexander G. <al...@in...> - 2002-06-03 23:17:45
|
On Fri, May 31, 2002 at 06:24:08PM -0500, Alexander Garden wrote: > On Fri, May 31, 2002 at 02:18:20PM -0700, Phlip wrote: > > Alexander Garden sez: > > > > > It ran away and was killed by the VOOM just a few minutes ago, so > > > something is leaking. > > > > Voom is the thing under the Y-cat's hat in /The Cat in the Hat Comes Back/, > > right? > > Oops, that should have been OOM killer. But you got it right anyway. > > Some people say it stands for 'Out Of Memory' killer, but I know better. > They also say it's a Linux kernel process that takes upon itself to > violently end the life of runaway processes. Yeah, right. > > > Apologies for running away, but if you disable the timer (grep def\ timer > > browser.py) will it stop leaking? > > I'll look into it. It only happened once, so I'm not sure if I can make > it repeat. It was leaking every time I ran it. Here's what I did to fix it: =========================================================== --- 002.browser/Debug.py Tue May 28 21:44:12 2002 +++ mybrowser/Debug.py Mon Jun 3 17:39:33 2002 @@ -93,10 +93,12 @@ try: raise None except: # TODO is there an inspect.py frame thing we could use here? - try: + #try: info = sys.exc_info() tb = info[2] frame = tb.tb_frame.f_back + del info + del tb code = frame.f_code file = [None, None] @@ -155,18 +157,20 @@ if len(expr) > 1: stringThing = "(" + stringThing + ")" report = '%s:%i: %s' % (file[0], frame.f_lineno, output) + del file if count (stringThing, "\n") > 0: - report += " =\n", + report += " =\n" else: - report += " = ", + report += " = " report += stringThing - sys.stderr(report) + sys.stderr.write(report) print report - except: - pass + #except: + #print "We're here" + #pass def tolerance(a, b): =========================================================== Of course, you don't want to apply that. The three added del statements fixed the problem, the rest is included because I want to ask questions. First, why is the whole thing wrapped up in a catch-all try/except that does nothing when an exception is raised? I commented this out because an exception was being raised every time. Second, the exception being raised was a TypeError because of the 'report += "...",' lines. Why the comma at the end? This makes the thing a tuple, which, to quote from the exception message, cannot be concatenated with a string object. (I tested this in 2.2 and got the same message.) Thirdly, the sys.stderr line raised an exception. I strongly suspect that's just because this way of invoking stderr was introduced in 2.1 or 2.2. Recall that I'm running 2.0. So you might want to change this for backwards compatibility. Or you might not. Whatever. And if you or someone else could clue me in as to why adding the explicit del statements could fix a memory leak here, I'd appreciate it. Maybe a 2.0 bug? Alexander |