question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uia APP.kill() bug

See original GitHub issue

I’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:

  1. 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:closed
  • Created 5 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
meshuggahtascommented, Mar 6, 2019

pywinauto 0.6.6 .kill(soft=True) sometimes throws this error:

ctypes.COMError: (-2147220991, ‘An event was unable to invoke any of the subscribers’, (None, None, None, 0, None))

Full log:

Traceback (most recent call last): File “C:/Users/oliver.horvath/PycharmProjects/pywinautogithub/main4.py”, line 10, in <module> APP.kill(soft=True) File “C:\Users\oliver.horvath\venv\pywinautogithub\Lib\site-packages\pywinauto-app_kill_bug\pywinauto\application.py”, line 1248, in kill win.close() File “C:\Users\oliver.horvath\venv\pywinautogithub\Lib\site-packages\pywinauto-app_kill_bug\pywinauto\controls\uiawrapper.py”, line 434, in close iface = self.iface_window File “C:\Users\oliver.horvath\venv\pywinautogithub\Lib\site-packages\pywinauto-app_kill_bug\pywinauto\controls\uiawrapper.py”, line 132, in get value = self.fget(obj) File “C:\Users\oliver.horvath\venv\pywinautogithub\Lib\site-packages\pywinauto-app_kill_bug\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-app_kill_bug\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))

Example code where I get this error thrown after 1~10 tries (seems like a timing related problem):

import pywinauto, time
from pywinauto import actionlogger
actionlogger.enable()

for i in range(0,30):
    print(i)
    APP = pywinauto.Application(backend="uia").start("magnify.exe")
    APP.Magnifier.set_focus()
    APP.Magnifier.Views.click()
    APP.kill(soft=True)

Otherwise the soft=True nicely closes the application (Magnify in my case), Edit:

  • Renamed dialog windows to english language in my example code.
  • As I see the error throws after APP.Magnifier.Views.click().
  • Here’s an extra log with an additional NULL COM pointer access and NoPatternInterfaceError traceback:

0 2019-03-06 10:22:04,655 INFO: Started magnify.exe application. 2019-03-06 10:22:06,762 INFO: Invoked button “Nézetek” 2019-03-06 10:22:06,983 INFO: Typed text to the Menu: {ESC} 2019-03-06 10:22:06,985 INFO: Closed window “Nagyító” 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(soft=True) File “C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\application.py”, line 1256, 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 937, in type_keys self.verify_actionable() File “C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py”, line 682, in verify_actionable self.verify_enabled() File “C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py”, line 692, in verify_enabled if not self.is_enabled(): File “C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\base_wrapper.py”, line 345, in is_enabled return self.element_info.enabled #and self.top_level_parent().element_info.enabled File “C:\Users\oliver.horvath\venv\pywinautogithub\lib\site-packages\pywinauto\uia_element_info.py”, line 321, in enabled return bool(self._element.CurrentIsEnabled) _ctypes.COMError: (-2147220991, ‘Az esemény nem tudott meghívni előfizetőt’, (None, None, None, 0, None))

1reaction
meshuggahtascommented, Dec 18, 2018

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Closing an application (fast) - python - Stack Overflow
app = pywinauto.application.Application(backend="uia") app.connect(path="myapplication.exe") app.kill(). This method often works.
Read more >
How it's possible to the app crash… | Apple Developer Forums
I'm having a hard time to debug a crash in our app. Our app is crashing in devices with iOS 9 and 10...
Read more >
pywinauto.application module - Read the Docs
Connect() to a running instance of that application. ... but the application will be killed anyway - you will not be able to...
Read more >
Had to kill the running app everytime for appium tests to run ...
Instruments Trace Error : Failed to start trace. info: [INSTSERVER] Instruments exited with code 253. error: Instruments did not launch successfully, failing ...
Read more >
pywinauto/pywinauto - Gitter
i am working on a project to automate a thirdparty app made on qt ... because it looks like dlg specification produced this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found