主要代码是这样的,采用多线程调用 process,process 再去调用其它函数
from multiprocessing.dummy import Pool as ThreadPool
import pythoncom
global wb
def process(r):
sht = wb.sheets["开户案例"]
sht.range((r,1)).value = '正在发送账户申请...'
result = accinfo(wb, r) #所在行,根据这个所在行,去进行后续操作
sht.range((r,1)).value = result
pool = ThreadPool(5)
list_args=[]
for r in rows:
list_args.append(r.row)
r1=pool.map(process, list_args)
pool.close()
pool.join()
提示的报错信息比较多
Traceback (most recent call last):
r1=pool.map(process, list_args)
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 260, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 608, in get
raise self._value
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\multiprocessing\pool.py", line 44, in mapstar
return list(map(*args))
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlwings\main.py", line 649, in sheets
return Sheets(impl=self.impl.sheets)
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlwings\_xlwindows.py", line 454, in sheets
return Sheets(xl=self.xl.Worksheets)
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\xlwings\_xlwindows.py", line 116, in __getattr__
v = getattr(self._inner, item)
File "C:\Users\zhangjw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\win32com\client\dynamic.py", line 516, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147417842, '应用程序调用一个已为另一线程整理的接口。', None, None)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.