Sign in to follow this  
Followers 0
hmsSurprise

Function time limits

5 posts in this topic

Was wondering if you know of a method for limiting the amount of time a function is allowed to run? Most of the functions I have in mind are not GUIs so haven't really considered a message loop. I suppose I could compile them and run them standalone and then kill the process if it runs too long. Any other ideas?

I have searched the forum and help but haven't found my particular application. Would appreciate the benefit of your experience.

Thanks,

jh

Share this post


Link to post
Share on other sites

Try look at TimerInit & TimerDiff in the help file.

Share this post


Link to post
Share on other sites

Try look at TimerInit & TimerDiff in the help file.

Thanks for posting.

Yes that would tell me how long a function had been running if the TimerDiff statement could be executed. I should have stated that I want to terminate a function that has run too long because it is hung, i.e. the timerDiff statement couldn't execute because it is after the hang.

jh

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

The function could be interrupted by lots of things, like GUI events, hot keys, or AdLibEnable(), but it would return to the function after handling those interrupts.

Something inside the called function would have to be monitoring an external flag, like a Global variable, or it could time itself with TimerInit() and TimerDiff().

Example of an external flag:

Global $Timeout = 0
Global $Time = TimerInit()

AdlibEnable("_TimeCheck", 100)
_MyFunc()
MsgBox(0, "Test", "Done.")

Func _MyFunc()
    $Pigs_Fly = False
    Do
        ; Loop forever
        If $Timeout Then ExitLoop
    Until $Pigs_Fly
EndFunc

Func _TimeCheck()
    ; Timeout at 30sec
    If TimerDiff($Time) > 30 * 1000 Then 
        $Timeout = 1
        AdlibDisable()
    EndIf
EndFunc

Just move the TimerInit()/TimerDiff() stuff inside the loop for the function to timeout itself internally.

:shocked:

P.S. Just saw the reply about a hung function. You can't 'kill' the function without exiting the script, but an AdLibEnable() timer like above could do some error processing and exit the script.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks,

Never would have thought to look for a something by the name AdlibEnable to help with timing out. This can work if I use ( quit being lazy) timeout options on all the WinWait type calls.

Think I will take a little time and briefly look at all the functions in the help file. Well maybe more than a little time....

Thanks again, sir.

jh

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