From b84d6ed07f8acf2ab25be2b31c64480ac3be66f6 Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@allmydata.com>
Date: Tue, 17 Apr 2007 20:29:08 -0700
Subject: [PATCH] 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

---
 src/allmydata/encode.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

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