質問編集履歴
1
改良版追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,4 +54,39 @@
|
|
54
54
|
i+=1
|
55
55
|
for process in process_list:
|
56
56
|
print(process.result())
|
57
|
+
```
|
58
|
+
↓
|
59
|
+
```改良版
|
60
|
+
items =[
|
61
|
+
{'blog': 'blog1', 'count': '111', 'user_name': 'user1'},
|
62
|
+
{'blog': 'blog2', 'count': '112', 'user_name': 'user2'},
|
63
|
+
{'blog': 'blog3', 'count': '113', 'user_name': 'user3'},
|
64
|
+
・
|
65
|
+
・
|
66
|
+
・
|
67
|
+
{'blog': 'blog1000', 'count': '11113', 'user_name': 'user1000'}
|
68
|
+
]
|
69
|
+
|
70
|
+
#リスト分ける
|
71
|
+
newList = split_list(items,100)
|
72
|
+
#スレッドプールを作る
|
73
|
+
tpe = ThreadPoolExecutor(max_workers=100)
|
74
|
+
|
75
|
+
for _ in range(newList.len):
|
76
|
+
tpe.submit(put_to_db)
|
77
|
+
tpe.shutdown()
|
78
|
+
print("完了")
|
79
|
+
|
80
|
+
|
81
|
+
#リストを分ける処理
|
82
|
+
def split_list(l, n):
|
83
|
+
for idx in range(0, len(l), n):
|
84
|
+
return l[idx:idx + n]
|
85
|
+
|
86
|
+
#DBに登録する処理
|
87
|
+
def put_to_db(Items):
|
88
|
+
|
89
|
+
table = dynamodb.Table('Movies')
|
90
|
+
for item in Items:
|
91
|
+
response = table.put_item(Item=item)
|
57
92
|
```
|