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.

pywinauto routinely takes 30s or more to find top_window()

See original GitHub issue

Expected Behavior

Better performance. Is there a way to speed this up? Where is all the time going? Should I profile it to find out?

Actual Behavior

Takes 30s+ to find top_window.

Short Example of Code to Demonstrate the Problem

import pywinauto, time
myexe = "" # Full path to the .exe file I'm automating
myargs = "" # arguments to it
myapp = pywinauto.application.Application(backend="uia").start(f'{myexe} "{myargs}"')
start=time.perf_counter()
mywindow = myapp.top_window()
end=time.perf_counter()
print(f"Took {end-start}s to find top window.")

Always 30s+ for me and the app starts rapidly, it just sits there as I do for a half minute waiting for top_window() to return.

Specifications

  • Pywinauto version: 0.6.8
  • Python version and bitness: 3.83 64 bit
  • Platform and OS: Windows 10

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
TesterNickcommented, Oct 11, 2021

Thank you for your reply! Yes, it is specific for “uia” only. Win32 takes nanoseconds, no matter of build type (wich is about 1000 times faster than what we consider “normal” for “uia”). sys.coinit_flags = 2 does not help.

1reaction
TesterNickcommented, Oct 7, 2021

I’ve faced the same issue: top_window() for the release build of our app takes less than 1 second, but when it comes to debug build, the same operation takes about 40 sec while the app is completely responsive. I asked a programmer about differences and got the answer: “Debug build starts additional COM server (which opens a lot of interfaces). Allegedly, pywinauto tries each available interface to find the suitable one.” Switching off the COM server made the time of the two builds comparable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

It takes a long time to find window using pywinauto
Still I think the time which is required could be reduced by using a more efficient code. I currently do this: app =...
Read more >
How To's — pywinauto 0.6.8 documentation
Dialog is a window containing several other GUI elements/controls like buttons, ... these get passed to the pywinauto.findwindows.find_elements() function.
Read more >
pywinauto.findwindows — pywinauto 0.6.8 documentation
It's a very low level API. Better use Application and WindowSpecification objects described in the Getting Started Guide. Possible values are: class_name ...
Read more >
Waiting for Long Operations — pywinauto 0.6.8 documentation
A GUI application behaviour is often unstable and your script needs waiting until a new ... that could help you to make your...
Read more >
Getting Started Guide — pywinauto 0.6.8 documentation
Once you have installed pywinauto - how do you get going? ... But Python can hide this wrapper_object() call so that you have...
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