English 中文(简体)
p子+窗口自动化——有时窗户冰川
原标题:python+windows automation - windows glitch sometimes

I m automating some windows stuff with Python, using PIL to take screenshots and such. the issue is that sometimes, deep in some function, I ll do a time.sleep(1) and the GUI app I m interfacing with will freeze for that second. This is weird cause doing time.sleep in other places doesn t cause the freeze. I haven t been able to determine exactly what causes the freeze and what doesn t.. it s happened both in threads besides the main thread and in the main thread.

任何想法? 我感到,像“冷静”功能一样,我只需要使沙德停止它所做的一切,让目标明确的“倡议”恢复,更新和处理投入,然后把它带回沙里。 这样做有什么作用? (窗口Sleep功能似乎与python s time.sleep。)

问题回答

I feel I just need like a "chill out" function to cause Python to stop whatever it is it s doing, let the targeted UI recover and refresh and process input, then bring it back to Python. What function would do that?

电话sleep((>)(其中任何一种变量)将阻止执行你称之为的透镜。 如果你愿意在这一read子中做出反应,这只是你想要做的最后一件事。 简言之,一旦你睡觉,你就可以做任何事情!

When you have non-responsive user interface, that indicates that a long-running task is executing in the thread which processes the UI, or the UI thread is blocking. So, to follow the logic through, if your 1 second sleeps (they are really dozes rather than proper sleeps!) are causing the UI to hang, they must be occurring in the same thread as the UI, or a thread which the UI is waiting.

我并不真正知道你是如何利用临时自治机构的,以及你如何与你正在 scrap弃的形象的人互动,但你似乎不大可能加入其他进程。 因此,我猜测,这一进程正等待着你。 如果是这样,解决你的问题就没有真正的捷径。 你们只需要花费较少的时间做你正在做的事情。 电话sleep()只会使情况恶化。

电话Switch ToThread() 也可大有助益。 这样做是为了让另一个人(如果有一个人等待并准备运行),但你希望你们的read能够运行。 它取得了巨大进步,因为该系统将知道,你的read子想要运行,并将在适当时候再次安排。

底线是,你有守则,在阻碍这一进程的团结互助会进程中运作。 你只是需要尽快做到,以尽量减少干扰。

也许你不想让现在的睡觉,而是让申请有机会处理其信息。

Since it s difficult to delegate to the application s main message pump, traditionally most long-running tasks call their own temporary message pump.

def process_messages():
    msg = wintypes.MSG ()
    while user32.GetMessageA (byref (msg), None, 0, 0) != 0:  
        user32.TranslateMessage (byref (msg))
        user32.DispatchMessageA (byref (msg))

微软-带式版本是:。 该法典将举办活动,介绍启动你read子的申请书,并在事件发生时返回。

我在沙尔和第三方图书馆观看了执行这一功能的比照,但并没有看到这种快速搜索。

简言之,在请您自发的<条码>程序_messages (功能时,如以视力基本语文和其他几个视窗语文做的那样,请你做上述工作,并避免打电话<条码>sleep(<>>)。

p.s. 只有在你重新等待任务完成之前,你才能把电泵抽出。

Oh Switch ToThread 似乎有希望。 或载于Adhury lingo,ctypes.windll.kernel32.Switch ToThread(

EDIT:Hmm don t 似乎完全如此......





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签