当前位置 : 主页 > 编程语言 > python >

python中的ThreadPoolExecutor

来源:互联网 收集:自由互联 发布时间:2022-06-21
#!/bin/env python3 import requests import datetime import threading import csv import json import random from concurrent.futures import ThreadPoolExecutor pool = ThreadPoolExecutor(16) threadLocal = threading.local() reader = csv.reader(ope
#!/bin/env python3

import requests
import datetime
import threading
import csv
import json
import random
from concurrent.futures import ThreadPoolExecutor

pool = ThreadPoolExecutor(16)
threadLocal = threading.local()

reader = csv.reader(open('***.csv'))
category = ['wilson1', 'wilson2', 'wilson3']


def push(i):
initialized = getattr(threadLocal, 'initialized', None)
if initialized is None:
threadLocal.initialized = True
threadLocal.s = requests.Session()
threadLocal.s.post(
'http://***/***',
json={
'username': 'admin',
'password': '1'
})
category_id = category.index(i[3])

threadLocal.s.post(
'http://***/***',
json={
'category_id': category_id,
'name': i[1],
'author': i[4],
})


for i in reader:
pool.submit(push, i)


网友评论