From: Brian Warner Date: Wed, 18 Apr 2007 03:29:08 +0000 (-0700) Subject: encode: fix multi-segment uploads: lambdas inside for loops require special attention... X-Git-Tag: tahoe_v0.1.0-0-UNSTABLE~71 X-Git-Url: https://git.rkrishnan.org/listings/frontends/status?a=commitdiff_plain;h=b84d6ed07f8acf2ab25be2b31c64480ac3be66f6;p=tahoe-lafs%2Ftahoe-lafs.git encode: fix multi-segment uploads: lambdas inside for loops require special attention to make sure you are capturing the *value* of the loop variable and not just the slot it lives in --- diff --git a/src/allmydata/encode.py b/src/allmydata/encode.py index 5b74f107..3731999d 100644 --- a/src/allmydata/encode.py +++ b/src/allmydata/encode.py @@ -151,7 +151,11 @@ class Encoder(object): d = defer.succeed(None) for i in range(self.num_segments-1): - d.addCallback(lambda res: self.do_segment(i)) + # note to self: this form doesn't work, because lambda only + # captures the slot, not the value + #d.addCallback(lambda res: self.do_segment(i)) + # use this form instead: + d.addCallback(lambda res, i=i: self.do_segment(i)) d.addCallback(lambda res: self.do_tail_segment(self.num_segments-1)) d.addCallback(lambda res: self.send_all_subshare_hash_trees())