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:
exitValue = runScript(script_b)
if exitValue == 1:
    "send me the warning message"
Everytime, I directly run script_a.
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

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

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

#-----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

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

Env.addHotkey(Key.END, KeyModifier.CTRL, Exit_Main)

while True:

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.