title: Python thread: The application called an interface that was marshalled for a different thread
body: <p>The following code works without errors:</p>
  
  <pre><code> self.sim.create_pnl_results(gui_values, dfs)
  </code></pre>
  
  <p>This code gives me an error:</p>
  
  <pre><code>thread = Thread(target=self.sim.create_pnl_results, args=(gui_values, dfs))
  thread.start()
  
  in _ApplyTypes_ self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
  com_error: (-2147417842, 'The application called an interface that was marshalled for a different thread.', None, None)
  </code></pre>
  
  <p>It seems that the application calls a com object somewhere further down the line and because I would like to put a gui (QT) on top I need to make it a separate thread. How can I avoid the above error message? I have read that it is connected to a windows problem. Any suggestions how to resolve it in python would be appreciated. I have no control on the com objects that are called from the application and I don't see why it would make a difference if I call them from the main thread of a new thread.</p>
  
  <p>additional information about how the com object is called:</p>
  
  <pre><code>def process_ts(*args):
      ts_id, i, dfn , ts_queue = args
      pythoncom.CoInitialize()
      ts = win32com.client.Dispatch(pythoncom.CoGetInterfaceAndReleaseStream(ts_id, pythoncom.IID_IDispatch))
      ts_queue.put( tuple([i , ACRF._com_to_ts(ts, i, dfn)]) )
      pythoncom.CoUninitialize ()
  </code></pre>