Nevow flat improvement
"John Benediktsson" <[email protected]> Tue, 7 Mar 2006 13:52:27 -0800
| Newsgroups | gmane.comp.python.quotient.dev |
|---|---|
| Message-ID | <B6FAC926EFE7B348B12F29CF7E4A93D452CD36@hammer.office.bhtrader.com> |
I found an improvement that can be made to nevow/flat/twist.py.
It doesn't look like divmod.org accepts anonymous tickets, so I am
posting this here.
The definition of deferflatten() causes cyclic references that force a
user to use the garbage collector to clean references to contexts
(PageContext, JavascriptContext, etc.) as well as other data referenced
by those contexts.
Any recursive inner function is self referencing and cannot be collected
by reference counting.
Basically the problem can be reduced to:
def f():
def g():
...
g()
g()
To fix this, you need to add a global statement:
def f():
global g
def g()
...
g()
g()
A patch is attached to show where the change could be made.
Thanks,
John Benediktsson
twist.py.patch
(application/octet-stream, 242 B)
--- twist.py.orig 2006-03-07 13:47:23.000000000 -0800
+++ twist.py 2006-03-07 13:47:32.000000000 -0800
@@ -7,6 +7,7 @@
def deferflatten(stan, ctx, writer):
+ global drive
finished = Deferred()
iterable = flat.iterflatten(