add more debug messages to log
[electrum-server.git] / backends / bitcoind / blockchain_processor.py
index 421f385..94cfbfa 100644 (file)
@@ -87,7 +87,8 @@ class BlockchainProcessor(Processor):
         self.memorypool_update()
         print_log("Memory pool initialized.")
 
-        threading.Timer(10, self.main_iteration).start()
+        self.timer = threading.Timer(10, self.main_iteration)
+        self.timer.start()
 
 
 
@@ -111,6 +112,7 @@ class BlockchainProcessor(Processor):
         try:
             respdata = urllib.urlopen(self.bitcoind_url, postdata).read()
         except:
+            print_log("error calling bitcoind")
             traceback.print_exc(file=sys.stdout)
             self.shared.stop()
 
@@ -252,6 +254,7 @@ class BlockchainProcessor(Processor):
                 hist = self.storage.get_history(addr)
                 is_known = True
             except:
+                print_log("error get_history")
                 self.shared.stop()
                 raise
             if hist:
@@ -446,7 +449,7 @@ class BlockchainProcessor(Processor):
                 if session in l:
                     l.remove(session)
                 if session in l:
-                    print "error rc!!"
+                    print_log("error rc!!")
                     self.shared.stop()
                 if l == []:
                     self.watched_addresses.pop(addr)
@@ -514,7 +517,7 @@ class BlockchainProcessor(Processor):
                 result = self.storage.get_address(txi)
             except BaseException, e:
                 error = str(e)
-                print_log("error:", error, txid, pos)
+                print_log("error:", error, params)
 
         elif method == 'blockchain.block.get_header':
             if cache_only:
@@ -596,6 +599,7 @@ class BlockchainProcessor(Processor):
         try:
             respdata = urllib.urlopen(self.bitcoind_url, postdata).read()
         except:
+            print_log("bitcoind error (getfullblock)")
             traceback.print_exc(file=sys.stdout)
             self.shared.stop()
 
@@ -748,10 +752,17 @@ class BlockchainProcessor(Processor):
             # TODO: update cache here. if new value equals cached value, do not send notification
             self.address_queue.put((address,sessions))
 
+    
+    def close(self):
+        self.timer.join()
+        print_log("Closing database...")
+        self.storage.close()
+        print_log("Database is closed")
+
+
     def main_iteration(self):
         if self.shared.stopped():
-            print_log("blockchain processor terminating")
-            self.storage.close()
+            print_log("Stopping timer")
             return
 
         with self.dblock:
@@ -794,7 +805,7 @@ class BlockchainProcessor(Processor):
                         'params': [addr, status],
                         })
 
-        if not self.shared.stopped():
-            threading.Timer(10, self.main_iteration).start()
-        else:
-            print_log("blockchain processor terminating")
+        # next iteration 
+        self.timer = threading.Timer(10, self.main_iteration)
+        self.timer.start()
+