import openpyxl
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures import ProcessPoolExecutor
from mytime import timeit
lis = {'Celery': 4, 'Garlic': 5, 'Lemon': 3.3}
# 创建数据更新函数
def update(name):
filename = '/root/Desktop/table2.xlsx'
wb = openpyxl.load_workbook(filename)
sheet = wb.active
try:
for index, row in enumerate(sheet.rows):
produceName = sheet.cell(row=index + 1, column=1).value
if produceName == name:
sheet.cell(row=index + 1, column=2, value=lis[name])
print('商品{}的信息更新完成..'.format(produceName))
except Exception as e:
print(e)
else:
wb.save(filename=filename)
# 多线程更新信息
@timeit
def thread():
with ThreadPoolExecutor(max_workers=4) as pool:
pool.map(update, lis)
# 多进程更新信息
@timeit
def pro():
with ProcessPoolExecutor() as pool:
pool.map(update, lis)
# thread()
pro()
#######linux操作系统#########
多线程时:
多进程时: