質問編集履歴
1
改良版追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -111,3 +111,73 @@
|
|
111
111
|
print(process.result())
|
112
112
|
|
113
113
|
```
|
114
|
+
|
115
|
+
↓
|
116
|
+
|
117
|
+
```改良版
|
118
|
+
|
119
|
+
items =[
|
120
|
+
|
121
|
+
{'blog': 'blog1', 'count': '111', 'user_name': 'user1'},
|
122
|
+
|
123
|
+
{'blog': 'blog2', 'count': '112', 'user_name': 'user2'},
|
124
|
+
|
125
|
+
{'blog': 'blog3', 'count': '113', 'user_name': 'user3'},
|
126
|
+
|
127
|
+
・
|
128
|
+
|
129
|
+
・
|
130
|
+
|
131
|
+
・
|
132
|
+
|
133
|
+
{'blog': 'blog1000', 'count': '11113', 'user_name': 'user1000'}
|
134
|
+
|
135
|
+
]
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
#リスト分ける
|
140
|
+
|
141
|
+
newList = split_list(items,100)
|
142
|
+
|
143
|
+
#スレッドプールを作る
|
144
|
+
|
145
|
+
tpe = ThreadPoolExecutor(max_workers=100)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
for _ in range(newList.len):
|
150
|
+
|
151
|
+
tpe.submit(put_to_db)
|
152
|
+
|
153
|
+
tpe.shutdown()
|
154
|
+
|
155
|
+
print("完了")
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
#リストを分ける処理
|
162
|
+
|
163
|
+
def split_list(l, n):
|
164
|
+
|
165
|
+
for idx in range(0, len(l), n):
|
166
|
+
|
167
|
+
return l[idx:idx + n]
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
#DBに登録する処理
|
172
|
+
|
173
|
+
def put_to_db(Items):
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
table = dynamodb.Table('Movies')
|
178
|
+
|
179
|
+
for item in Items:
|
180
|
+
|
181
|
+
response = table.put_item(Item=item)
|
182
|
+
|
183
|
+
```
|