Improve invoke() method to avoid hang problems
See original GitHub issueThis ia a new issue based in the discussion that started in https://github.com/pywinauto/pywinauto/issues/865
Basically, sometimes invoke()
is raising a generic exception.
>>> loginButton.click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\diego.queiroz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pywinauto\controls\uia_controls.py", line 121, in click
self.invoke()
File "C:\Users\diego.queiroz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pywinauto\controls\uiawrapper.py", line 513, in invoke
self.iface_invoke.Invoke()
_ctypes.COMError: (-2147220991, 'event cannot call any subscribers', (None, None, None, 0, None))
Despite the exception, the button is clicked as expected. The current workaround is to just ignore the exception, as follows:
try:
loginButton.click()
except:
pass # ignore
# script continues here
This may be happening because the application is not returning in a timely manner (indeed, the application I am testing freezes for a second when I click the login button). Probably a improvement like a configurable timeout may solve this problem.
Also, it would be interesting to raise a more specific exception when an error like this happens.
@vasily-v-ryabov said:
Sometimes we also face with hang problem when calling .invoke() (.click() is an alias of .invoke() for ButtonWrapper). It means we need to create a separate thread with some timeout and print a warning if it is timed out. This is also separate issue, but we can combine it in one issue since it is all in .invoke() method.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8 (4 by maintainers)
@celsolarussa The current workaround is to just ignore the exception, as shown in the first message.
We will try to improve backward compatibility before release. But this particular feature is implemented and I’m closing the issue to help us tracking progress for 0.7.0 milestone. Thanks for understanding! I will notify when new release is out.