Open flriancu opened 3 years ago
it seems like the SO post is referring to keeping a single COM application alive to re-use in multiple threads but still in a somewhat .. sequential manner if I understand correctly? they want to re-use it in subsequent ajax requests
I think what you're trying to do seems a little bit different in that you want to use it concurrently
perhaps you can try using concurrent.futures.ProcessPoolExecutor
to start to see if concurrency with win32com works at all? if so, we can re-visit getting it to work with threads
I think what you're trying to do seems a little bit different in that you want to use it concurrently
Yes, precisely, I'm trying to use concurrently.
[...] to see if concurrency with win32com works at all
Yes, I plan to build a minimum reproducible example as soon as possible, I just haven't had the time.
On the other hand, I did get around this issue, at least as a short-term solution, as below, for all calls in all threads:
pythoncom.CoInitialize()
docx2pdf.convert(...)
related to #28
Same issue here. What should we do ?
EDIT:
My probolem solved with @flriancu 's solution. Here is a thread which describes what exactly this method does :
I had the exact same problem. This solution also worked for me. Thanks @flriancu
pythoncom.CoInitialize() docx2pdf.convert(...)
Configuration:
The
convert
function will sometimes yield(-2147221008, 'CoInitialize has not been called.', None, None)
. I'm currently working to figure out the exact steps to reproduce, but I might not be able to, since the overall application is multithreaded (viaconcurrent.futures.ThreadPoolExecutor
, where one of the tasks callsconvert
) and seems to happen at random.As far as I know, using
win32com
in Python requires callingpythoncom.CoInitialize()
- see this post for an example.