getdata: catch all exceptions properly and resume when requesting daemon

gh-pages
stoffu 1 year ago
parent f924f65081
commit 0038f51bb1

@ -43,6 +43,8 @@ import sys
import datetime
import json
import requests
import urllib3
import time
class GetData():
def run(self, port, height_window_index):
@ -60,7 +62,10 @@ class GetData():
try:
res_blk = daemon.getblock(i)
break
except requests.exceptions.RequestException as e:
except (Exception, OSError, requests.exceptions.ConnectionError, urllib3.exceptions.MaxRetryError, urllib3.exceptions.NewConnectionError) as e:
print('daemon.getblock() at height', i, ", error", e, file=sys.stderr)
print('Sleeping for a second', file=sys.stderr)
time.sleep(1)
continue
block_header = res_blk['block_header']
@ -76,7 +81,15 @@ class GetData():
# print(res_blk)
# print('====================================================')
res_txs = daemon.gettransactions(res_blk['tx_hashes']) if num_txes > 0 else None
while True:
try:
res_txs = daemon.gettransactions(res_blk['tx_hashes']) if num_txes > 0 else None
break
except (Exception, OSError, requests.exceptions.ConnectionError, urllib3.exceptions.MaxRetryError, urllib3.exceptions.NewConnectionError) as e:
print('daemon.gettransactions() at height', i, ", error", e, file=sys.stderr)
print('Sleeping for a second', file=sys.stderr)
time.sleep(1)
continue
txs_str = ''
for j in range(num_txes):
tx_json = res_txs['txs'][j]['as_json']

Loading…
Cancel
Save