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:
parent
a4d7607a9e
commit
b84d6ed07f
|
@ -151,7 +151,11 @@ class Encoder(object):
|
||||||
d = defer.succeed(None)
|
d = defer.succeed(None)
|
||||||
|
|
||||||
for i in range(self.num_segments-1):
|
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.do_tail_segment(self.num_segments-1))
|
||||||
|
|
||||||
d.addCallback(lambda res: self.send_all_subshare_hash_trees())
|
d.addCallback(lambda res: self.send_all_subshare_hash_trees())
|
||||||
|
|
Loading…
Reference in New Issue