comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Uncaught COMError with Automation in shell results in a leak

Open jcjf opened this issue 11 years ago • 0 comments

In either the CPython or IPython interactive shells:

>>> import comtypes.client
>>> xl = comtypes.client.CreateObject('Excel.Application', dynamic=True)
>>> wb = xl.Workbooks.Open('nonexistent.xlsx')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python33\lib\site-packages\comtypes\client\lazybind.py", line 182, in caller
    return self._comobj._invoke(descr.memid, descr.invkind, 0, *args)
  File "C:\Python33\lib\site-packages\comtypes\automation.py", line 729, in _invoke
    dp, var, None, argerr)
_ctypes.COMError: (-2146827284, None, ("'nonexistent.xlsx' could not be found. Check the spelling of the file name, and verify that the file location is correct.\n\nIf you are trying to open the file from your list of most recently used files, make sure that the file has not been renamed, moved, or deleted.", 'Microsoft Office Excel', 'C:\\Program Files (x86)\\Microsoft Office\\Office12\\1033\\XLMAIN11.CHM', 0, None))
>>> xl.Quit()
>>> del xl

Task Manager shows that an EXCEL.EXE instance still lingers. If I wrap the above inside a try statement with except: pass, then Excel shuts down.

jcjf avatar Oct 05 '14 10:10 jcjf