Sign in to follow this  
Followers 0
Guest CitizenBob

Handling Runaway Process

4 posts in this topic

I'm automating some software that occaisionally gets into an infinite (> 12 hour) loop. While in this state it inconveniently hogs all of the cpu. My AutoIt script is coded to timeout after 10 seconds, then kill the runaway process and restart. The problem is that AutoIt never times out of the WinWaitActive call.

Setting priorities in the task manager has no effect. However, if I throw up a message box then dismiss it before waiting, AutoIt gets the attention it deserves, and everything works splendidly (although the actual timing is a little skewed towards waiting too long, but that's ok).

Remove the semicolon in the code below, and everything is hunky-dory.

Func PasteNameAsStructure($chemicalName)

ClipPut($chemicalName)

Send("!e")

Send("s")

Send("n")

; MsgBox(4096, "Message", "Pasted", 1)

WinWaitActive("ChemDraw Ultra", "OK", 10)

While WinActive("ChemDraw Ultra", "Cancel") == 1

Send("{enter}")

WinWaitActive("ChemDraw Ultra", "OK", 10)

WEnd

If WinActive("ChemDraw Ultra", "OK") == 1 Then

Send("{enter}")

Return -1

EndIf

Return 0

EndFunc

So the question in all of this: is there a less hacky way of dealing with this problem? I don't like my message box solution. I'm a win32 process neophite and an AutoIt newbie; I'm hoping there's an obvious solution under my nose.

Incidentally, I increased the window delay time to 1s, which didn't solve the problem, but qualitatively improved the timeout accuracy (I haven't done a rigorous verification of this). But I don't want to increase this value too much, because the common case is that the window becomes immediately active, and I want to chug through these cases as quickly as possible.

Any suggestions are appreciated.

Cheers,

Scott

Share this post


Link to post
Share on other sites



to keep AutoIt from hogging up the CPU, put a tiny sleep in it, or code it with adlib:

AdlibEnable ("lowcpu",1); do this to keep CPU happy

While 1
Wend


Func lowcpu()
    sleep(10); you can use sleep(1) if you like.
EndFunc

comment out the adlib and watch your CPU usage fly.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

oops missed the actual question, must be a bit early for me..

ok,

it might not be actually active I am thinking, try this.

; MsgBox(4096, "Message", "Pasted", 1)
WinWait("ChemDraw Ultra", "OK")
Winactivate("ChemDraw Ultra", "OK")
WinWaitActive("ChemDraw Ultra", "OK", 10)
While WinActive("ChemDraw Ultra", "Cancel") == 1

you can also loop it to keep trying to activate it as well.

It looks to me like the window is not getting focus.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

I think I need to elaborate a bit more. The issue is subtle.

In the case of the runaway process, I want the WinWaitActive to fail. That is, once the process completes, it throws up a window (with an OK button) indicating that it completed. I want to catch that dialog ASAP, and return from the function. If the process still hasn't completed in 10 seconds, I want to give up and continue anyway. The problem is that the timeout isn't working correctly (unless I do my MsgBox trick). I'm speculating that the timeout doesn't work correctly because AutoIt isn't getting *enough* cpu cycles. I'm also speculating that the MsgBox somehow causes AutoIt to get more attention from the cpu.

The while loop is a bit of a red-herring, it's handling another (rare) case where the process throws up a window with an OK and a CANCEL button that is asking a question. In the case that I'm describing, it's not being executed at all.

Cheers,

Scott

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0