Detaching life fragments bug - how do I proceed
Werner Thie <[email protected]> Mon, 26 Jul 2010 11:12:52 +0200
| Newsgroups | gmane.comp.python.quotient.dev |
|---|---|
| Organization | THIE Projects & Co |
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--------------010709070206030701080806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Hi all
Any advice on how to proceed with moving the solution below to the
following problem into nevow trunk?
Attaching/Detaching LiveElements is a lot of fun but while ensuring that
everything got detached I stumbled over the problem that out of 36
fragments only 18 (the even numbered ones) received a detach call. This
pattern smelled a lot like there is an iteration over a list happening
while somewhere in the code items are removed from the list. A quick
debugging session confirmed that this is in fact so. Consider the
original code on the server in nevow/athena for:
def _athenaDetachServer(self):
"""
Locally remove this from its parent.
@raise OrphanedFragment: if not attached to a parent.
"""
if self.fragmentParent is None:
raise OrphanedFragment(self)
for ch in self.liveFragmentChildren:
ch._athenaDetachServer()
self.fragmentParent.liveFragmentChildren.remove(self)
self.fragmentParent = None
self.page = None
self.detached()
expose(_athenaDetachServer)
which detaches every other liveFragmentChildren, whereas the code below
detaches all liveFragmentChildren, working with a copy of the list while
iterating:
def _athenaDetachServer(self):
"""
Locally remove this from its parent.
@raise OrphanedFragment: if not attached to a parent.
"""
if self.fragmentParent is None:
raise OrphanedFragment(self)
#need a copy the children's list for undisturbed cleanup
for ch in list(self.liveFragmentChildren):
ch._athenaDetachServer()
self.fragmentParent.liveFragmentChildren.remove(self)
self.fragmentParent = None
self.page = None
self.detached()
expose(_athenaDetachServer)
The same holds true for the client code in nevow/js/__init__.js, where
function _athenaDetachClient(self) {
for (var i = 0; i < self.childWidgets.length; ++i) {
self.childWidgets[i]._athenaDetachClient();
}
if (self.widgetParent !== null) {
self.widgetParent.removeChildWidget(self);
}
delete Nevow.Athena.Widget._athenaWidgets[self.objectID];
self.detached();
},
becomes
function _athenaDetachClient(self) {
var childWidgets = [];
//need a copy the children's list for undisturbed cleanup
for (var i = 0; i < self.childWidgets.length; ++i) {
childWidgets[i] = self.childWidgets[i];
}
for (var i = 0; i < childWidgets.length; ++i) {
childWidgets[i]._athenaDetachClient();
}
if (self.widgetParent !== null) {
self.widgetParent.removeChildWidget(self);
}
delete Nevow.Athena.Widget._athenaWidgets[self.objectID];
self.detached();
},
Thanks, Werner
--------------010709070206030701080806
Content-Type: text/x-vcard; charset=utf-8;
name="werner.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="werner.vcf"
begin:vcard
fn:Thie Werner
n:Thie;Werner
org:THIE Projects & Co
adr:;;Oberdorfstr 8;Lachen;SZ;8853;Switzerland
email;internet:[email protected]
tel;work:+41 52 238 12 50
tel;fax:+41 52 238 12 51
tel;home:+41 52 233 21 91
tel;cell:+41 78 936 21 91
x-mozilla-html:FALSE
version:2.1
end:vcard
--------------010709070206030701080806
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline