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

This commit is contained in:
Brian Warner 2007-04-17 20:29:08 -07:00
parent a4d7607a9e
commit b84d6ed07f
1 changed files with 5 additions and 1 deletions

View File

@ -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())