Monitor whether a script is running but frozen for a while

Asked by BOCHENG YIN on 2019-07-17

I am running sikulix to automate the photo-labeling cross the sample surface on a microscope. The surface is split into many tiles which the sikulix will manipulate to loop through. The whole process is time-consuming and man-unattended.

I have script_a and script_b. script_b does the trivial jobs at every tile and loop through the tiles.
script_a will call script_b and send me a warning message when script_b crashes:
i.e.
exitValue = runScript(script_b)
if exitValue == 1:
    "send me the warning message"
Everytime, I directly run script_a.
However,
there is an occasion that script_b does NOT crash but freeze for a long time without being noticed.
I don't know which step in script_b will be strangled.
What I propose to do is firstly to log a time when script_b initiates in a txt file, then a code can keep monitoring the system time. If the time passed by is longer than a certain time (saying 30 min), a warning message will be triggered and sent to me.
I don't know how to make it work properly as it sounds like I need two sikulix scripts run simultaneouly.
There could be a better solution than my proposal.
I use window 7, sikulix IDE 1.1.4 currently.
Please guide me to deal with this problem. Thanks a lot!

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2019-07-17
Last reply:
2019-07-17
masuo (masuo-ohara) said : #1

There is a way to use thread module.
This script will exit after 10 seconds.

[example]
#-----count down and type hotkey
def Type_Hotkey(name,*args):
    cnt = args[0]
    while cnt > 0:
        cnt = cnt - 1
        Do.popup("%d" % cnt, "remaining time", 1)
    type(Key.END,Key.CTRL) #type hotkey

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

#-----Main script
import thread
duration = 10

Env.addHotkey(Key.END, KeyModifier.CTRL, Exit_Main)
thread.start_new_thread(Type_Hotkey,("Type_Hotkey",duration))

while True:
    sleep(5)

Can you help with this problem?

Provide an answer of your own, or ask BOCHENG YIN for more information if necessary.

To post a message you must log in.