made ReplyMatcher not resend queries and made the example in bitcoin.p2p handle timeouts
authorForrest Voight <forrest@forre.st>
Thu, 15 Dec 2011 10:47:40 +0000 (05:47 -0500)
committerForrest Voight <forrest@forre.st>
Sat, 17 Dec 2011 09:37:00 +0000 (04:37 -0500)
p2pool/bitcoin/p2p.py
p2pool/util/deferral.py

index a6392e7..7bd2f8c 100644 (file)
@@ -395,7 +395,10 @@ if __name__ == '__main__':
     @apply
     @defer.inlineCallbacks
     def think():
-        print (yield (yield factory.getProtocol()).get_block(0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175))
+        try:
+            print (yield (yield factory.getProtocol()).get_block(0x000000000000003aaaf7638f9f9c0d0c60e8b0eb817dcdb55fd2b1964efc5175))
+        except defer.TimeoutError:
+            print "timeout"
         reactor.stop()
     
     reactor.run()
index 4a5e1a5..738326a 100644 (file)
@@ -41,7 +41,8 @@ class ReplyMatcher(object):
         self.map = {}
     
     def __call__(self, id):
-        self.func(id)
+        if id not in self.map:
+            self.func(id)
         df = defer.Deferred()
         def timeout():
             self.map[id].remove((df, timer))