import openpyxl from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ProcessPoolExecutor import time # 创建数据更新函数 def update(name, price): 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=price) except Exception as e: print(e) else: wb.save(filename=filename) # 多线程更新信息 # start = time.time() # with ThreadPoolExecutor(max_workers=4) as poor: # poor.submit(update, 'Celery', 3.7).result() # poor.submit(update, 'Garlic',9.4).result() # poor.submit(update, 'Lemon', 2.4).result() # end = time.time() # print('信息更新完成...多线程用时%s' % (end - start)) #多进程更新信息 start = time.time() with ProcessPoolExecutor(max_workers=4) as poor: poor.submit(update, 'Celery', 3.7).result() poor.submit(update, 'Garlic',9.4).result() poor.submit(update, 'Lemon', 2.4).result() end = time.time() print('信息更新完成...多进程用时%s' % (end - start))
#######linux操作系统#########
多线程时:
多进程时:
转载请标明出处:多进程多线程更新信息
文章来源: 多进程多线程更新信息