Прервать операцию pywinautoPython

Программы на Python
Anonymous
Прервать операцию pywinauto

Сообщение Anonymous »


I have a program that operates an external application using a thread. I want to be able call the abort() method of the thread to close the external application and immediately cease all pywinauto operations. Here is a simplified version of my attempt:

from pywinauto.application import Application import threading import time class MyThread(threading.Thread): def run(self): self.app = Application().start('C:\\WINDOWS\\system32\\notepad.exe') window = self.app.window(title='Untitled - Notepad') window.wait('ready') while True: window.menu_select('Edit->Select All') def abort(self): self.app.kill() print("abort method complete") thread = MyThread() thread.start() time.sleep(2) thread.abort() When run, it waits 2 seconds as expected, then prints "abort method complete", and then there is a long delay and a pywinauto.timings.TimeoutError and pywinauto.findwindows.ElementNotFoundError are raised. That is a sign that pywinauto is still running the menu_select operation even after app.kill().

Is there any method to get pywinauto to immediately cease any active operations?


Источник: https://stackoverflow.com/questions/597 ... -operation

Вернуться в «Python»