-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
81 lines (50 loc) · 1.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /usr/bin/env python
# coding: utf-8
# Licensed under the MIT License.
from Block.RpcClient import RpcClient
import time
import os
from multiprocessing import Pool, cpu_count
from binascii import unhexlify
from utils.tools import Tool
from binascii import unhexlify
from dotenv import load_dotenv, find_dotenv
import logzero
from logzero import logger
from handle import save_block,del_all,create_index
from utils.tools import get_random_node
logzero.logfile(os.getcwd() + "/log/main.log", maxBytes=1e10, backupCount=1)
load_dotenv(find_dotenv(), override=True)
work_count = cpu_count()
def main(b):
try:
start = time.time()
# ## random node
# node = get_best_node()
# if node == '':
# return
r = b.get_block_count()
print('get_block_count',r)
skip = 1000
pool = Pool(processes=work_count)
for x in range( 0 , r - 1, skip):
print('x', x)
pool.apply_async(save_block, args=(b, x, skip - 1)) # 非阻塞
pool.close()
pool.join()
end = time.time()
logger.info('main %.3f seconds.' % (end - start))
except Exception as e:
#print('err', e)
logger.exception(e)
time.sleep(5)
b = RpcClient()
b.url = get_random_node()
main(b)
if __name__ == "__main__":
try:
logger.info('main start')
b = RpcClient()
main(b)
except Exception as e:
logger.exception(e)