title: win32com.client.Dispatch + Cherrypy = CoInitialize has not been called
body: <p>The following code works well, but it fails if executed from a CherryPy app method with the error message <code>CoInitialize has not been called</code>:</p>
  
  <pre><code>import win32com.client
  xl = win32com.client.Dispatch("Excel.Application")
  xl.quit()
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/12230240/how-to-use-python-and-windows-com-in-pyramid-threads#answer-12234275">This post</a> suggests a solution that works for me:</p>
  
  <pre><code>import pythoncom
  pythoncom.CoInitialize()
  </code></pre>
  
  <p>The reason I'm asking about a problem for which I already have a solution, is that (1) I would like to know what I'm doing (rather than doing it only because I've seen it working once) and (2) I don't want to risk to miss something important (and reading <a href="https://stackoverflow.com/questions/16469182/coinitialize-has-not-been-called-error-message">this post</a> makes me think that I am missing something.)</p>
  
  <p>I couldn't find any documentation for <code>pythoncom.CoInitialize()</code>, and the source of pythoncom is the following three lines that don't help me (nor Eclipse+pydev which says that the method does not exist):</p>
  
  <pre><code># Magic utility that "redirects" to pythoncomxx.dll
  import pywintypes
  pywintypes.__import_pywin32_system_module__("pythoncom", globals())
  </code></pre>