set time duration to run script

Asked by Sandy Mendoza on 2017-05-05

Hi Sirs,

Is it possible to set specific time duration to run a script and end it after it reached the time ?
I hope someone can help me with this..
Thanks in advance..

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
masuo (masuo-ohara) said : #1

This is sample codes for self countdown timer.

[sample code:]
import thread

#-----count down and type hotkey
def Type_Hotkey(name,*args):
    cnt = args[0]
    while cnt > 0:
        cnt = cnt - 1
    type(Key.END,Key.CTRL) #type hotkey

#-----hotkey handler
def Exit_Main(event):
    type(Key.CTRL) #dummy type to cancel CTRL

#-----Main script
Env.addHotkey(Key.END, KeyModifier.CTRL, Exit_Main)
duration = 5
while True:

RaiMan (raimund-hocke) said : #2

@masuo: interesting solution ;-)
... but in SikuliX scripts one should never use sys.exit() but exit() to assure the SikuliX internal cleanup.

... hence:
#-----hotkey handler
def Exit_Main(event):
    type(Key.CTRL) #dummy type to cancel CTRL

masuo (masuo-ohara) said : #3

@RaiMan: Thank you for your correction.

Can you help with this problem?

Provide an answer of your own, or ask Sandy Mendoza for more information if necessary.

To post a message you must log in.