多进程多线程更新信息

匿名 (未验证) 提交于 2019-12-03 00:28:02
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操作系统#########

多线程时:


多进程时:



转载请标明出处:多进程多线程更新信息
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!