multithreading rtf to pdf using python multiprocessing library -
i have created small python code opens word document , saves pdf. trying make faster using multi threading running weird error.
import sys import os,os.path import win32com.client import time multiprocessing import pool wdformatpdf = 17 input_dir = r'l:\outtable' output_dir = r'l:\outpdf' filter_files = '' files= os.listdir(input_dir.strip()) file2=[] file in files: if 'rtf' in file , not ('~' in file): file2.append(file) def printpdf(pfile): if 'rtf' in pfile , not('~' in pfile): in_file = input_dir.strip()+"\\"+pfile print (in_file) output_file = pfile.split('.')[0] out_file = output_dir+"\\"+output_file+'.pdf' word= win32com.client.dispatch('word.application') word.visible = false try: doc= word.documents.open(in_file) doc.saveas(out_file, fileformat=wdformatpdf) doc.close(savechanges=false) except exception e: print ('check file',out_file) print (str(e)) word.quit() if __name__== "__main__": p=pool(10) p.map(printpdf,file2)
---error:
multiprocessing.pool.remotetraceback: """ traceback (most recent call last): file "c:\python34\lib\multiprocessing\pool.py", line 119, in worker result = (true, func(*args, **kwds)) file "c:\python34\lib\multiprocessing\pool.py", line 44, in mapstar return list(map(*args)) file "c:\users\nyspa\desktop\data\codes\multi thread pdf.py", line 24, in printpdf word.visible = false file "c:\python34\lib\site-packages\win32com\client\dynamic.py", line 576, in __setattr__ raise attributeerror("property '%s.%s' can not set." % (self._username_, attr)) attributeerror: property 'word.application.visible' can not set. """ above exception direct cause of following exception: traceback (most recent call last): file "c:\users\nyspa\desktop\data\codes\multi thread pdf.py", line 35, in <module> p.map(printpdf,file2) file "c:\python34\lib\multiprocessing\pool.py", line 260, in map return self._map_async(func, iterable, mapstar, chunksize).get() file "c:\python34\lib\multiprocessing\pool.py", line 599, in raise self._value attributeerror: property 'word.application.visible' can not set.
i looks somewhere along line pool of thread getting broken. not expert on multiprocessing, gathered code here , there , converts files stops. can point out going on?
not software threadable. seems converter belongs class of software. that's not surprising, considering you're talking process via interface – how should word process know there's multiple threads talking it?
so, technologically impossible multithread thing – need ms word process multiple files in parallel.
Comments
Post a Comment