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.

Improve invoke() method to avoid hang problems

See original GitHub issue

This 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:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
DiegoQueirozcommented, Aug 24, 2021

@celsolarussa The current workaround is to just ignore the exception, as shown in the first message.

try:
  loginButton.click()
except:
  pass # ignore exception

# script continues here
0reactions
vasily-v-ryabovcommented, May 12, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Control.Invoke is hanging - Stack Overflow
It happens when the main thread of the program, the UI thread, is not idle and busy doing something else.
Read more >
How to make thread-safe calls to controls - Windows Forms .NET
Use the System.Windows.Forms.Control.Invoke method to call a delegate created in the main thread, which in turn calls the control. Or, implement ...
Read more >
Use PyQt's QThread to Prevent Freezing GUIs - Real Python
In this step-by-step tutorial, you'll learn how to prevent freezing GUIs by offloading long-running tasks to worker QThreads in PyQt.
Read more >
Troubleshoot invocation issues in Lambda
Error handling options and retry behavior vary depending on how you invoke your function and on the type of error. For a list...
Read more >
The 10 Most Common JavaScript Issues Developers Face
Alternatively, in newer browsers, you can use the bind() method to pass in the proper ... JavaScript issues if you're not consciously coding...
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