set time duration to run script

Asked by Sandy Mendoza

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

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
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
        sleep(1)
    type(Key.END,Key.CTRL) #type hotkey

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

#-----Main script
Env.addHotkey(Key.END, KeyModifier.CTRL, Exit_Main)
duration = 5
thread.start_new_thread(Type_Hotkey,("Type_Hotkey",duration))
while True:
    sleep(1)

Revision history for this message
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
    exit()

Revision history for this message
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.