uia APP.kill() bug
See original GitHub issueI’m not sure about this, but my observation is that APP.kill() depending on the state of the program throws an error or “halfly terminates” probably because of trying to press ESC on a non existing control/window.
Example 1 : windows magnifier. This only happens, when you click on the dropdown menu AND the window itself was focused.
Example 2 : OBS. This only happens, when the Stats dialog is open AND the OBS window itself was focused.
Example 3 : windows magnifier half termination -> simple example code is APP = pywinauto.Application(backend="uia").start("magnify.exe") and APP.kill(). If you have docked magnifier, the top of the screen remains “docked”. Also I have high confidence in that the application still lingers in the background/memory (huge performance drop while writing this issue), have no idea if this is directly related to pywinatuo APP.kill().
Example 1 code (Make sure to rename “Nagyito” to Magnifier maybe, name of the window and “Nezetek” to Views maybe, the dropdown with 3 values):
import pywinauto
from pywinauto import actionlogger
actionlogger.enable()
APP = pywinauto.Application(backend="uia").start("magnify.exe")
APP.Nagyito.set_focus() # name of the window maybe Magnifier
APP.Nagyito.Nezetek.click_input() # name of the dropdown maybe Views
APP.kill()
Result of above code:
2018-08-15 11:48:47,341 INFO: Started magnify.exe application.
2018-08-15 11:48:48,710 INFO: Clicked Button "Nézetek" by left button mouse click at (267, 354)
2018-08-15 11:48:49,165 INFO: Typed text to the Menu: {ESC}
Traceback (most recent call last):
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\uia_defines.py", line 232, in get_elem_interface
iface = cur_ptrn.QueryInterface(cls_name)
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\comtypes\__init__.py", line 1158, in QueryInterface
self.__com_QueryInterface(byref(iid), byref(p))
ValueError: NULL COM pointer access
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 434, in close
iface = self.iface_window
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 322, in iface_window
return uia_defs.get_elem_interface(elem, "Window")
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\uia_defines.py", line 234, in get_elem_interface
raise NoPatternInterfaceError()
pywinauto.uia_defines.NoPatternInterfaceError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/oliver.horvath/PycharmProjects/pywinautogithub/main4.py", line 10, in <module>
APP.kill()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\application.py", line 1247, in kill
win.close()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 440, in close
self.type_keys("{ESC}")
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py", line 882, in type_keys
self.verify_actionable()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py", line 626, in verify_actionable
self.verify_visible()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py", line 649, in verify_visible
raise ElementNotVisible()
pywinauto.base_wrapper.ElementNotVisible
Example 2 is with OBS:
- Enable the option “Open Stats dialog on startup” in General, 2nd option maybe.
import pywinauto
from pywinauto import actionlogger
actionlogger.enable()
APP = pywinauto.Application(backend="uia").start(work_dir=r"C:\Program Files (x86)\obs-studio\bin\64bit", cmd_line=r"C:\Program Files (x86)\obs-studio\bin\64bit\obs64.exe")
APP.Dialog.set_focus() # OBS window
APP.kill()
Result of above code:
Traceback (most recent call last):
File "C:/Users/oliver.horvath/PycharmProjects/pywinautogithub/main4.py", line 11, in <module>
APP.kill()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\application.py", line 1247, in kill
win.close()
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 434, in close
iface = self.iface_window
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 132, in __get__
value = self.fget(obj)
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\controls\uiawrapper.py", line 322, in iface_window
return uia_defs.get_elem_interface(elem, "Window")
File "C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\uia_defines.py", line 231, in get_elem_interface
cur_ptrn = element_info.GetCurrentPattern(ptrn_id)
_ctypes.COMError: (-2147220991, 'Az esemény nem tudott meghívni előfizetőt', (None, None, None, 0, None))
Translation of last line: “The event was unable to invoke a subscriber”.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (8 by maintainers)

Top Related StackOverflow Question
pywinauto 0.6.6
.kill(soft=True)sometimes throws this error:Full log:
Example code where I get this error thrown after 1~10 tries (seems like a timing related problem):
Otherwise the
soft=Truenicely closes the application (Magnify in my case), Edit:APP.Magnifier.Views.click().NULL COM pointer accessandNoPatternInterfaceError traceback:You are right. Example 2 also works flawlessly, so the bugs written in this issue are solved by that app_kill_bug tree 😃 (Issue can be closed)