Python Threading With Excel Com Object
<p>I am trying to open a workbook using a pre-opened excel com object within a python thread. Using the below code:</p>

<pre><code>from multiprocessing import Process, Queue

def open_workbook(excel,iSub_Loc,q):
    p = Process(target = open_workbook_helper, args = (excel,iSub_Loc))
    p.daemon = True
    p.start()

def open_workbook_helper(excel,iSub_Locq,):
    wb = excel.Workbooks.Open(iSub_Loc)
    ws = wb.Sheets(1)
    q.put((wb,ws))
</code></pre>

<p>but i get the following error</p>

<p><code>Can't pickle &lt;type PyIDispatch'&gt;: it's not found as __builtin__.PyIDispatch</code></p>

<p>any suggestions? </p>

<p>"multiprocessing" is not "threading" - Use <code>from threading import Thread, Queue</code> instead.
WHat happnes is that for inter-process comunication the dtaa is serialized to make the calls to the code on the other process, and COM objects use system resources that are not serializable.</p>

<p>If the operations you need to perform on your data are IOBound, just using threads will fit you. If you have code that would take advantage of multiple cores in pure Python - with sheer computation, then you can a separate process with just your data - already on Python side - not the COM objects. </p>

python excel multithreading com-object