sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #17288
Re: [Question #225815]: How to exit a script inside a group of batch scripts without stop running the other scripts
Question #225815 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/225815
Status: Open => Answered
RaiMan proposed the following answer:
Since execfile() runs the code in the context of your mainscript, using
exit() will always terminate your whole script.
Normally, one would pack the code of each script into a def(), import the subscript (which would solve the image problem too) and call the def, which simply returns, when finished.
see http://doc.sikuli.org/globals.html#importing-other-sikuli-scripts-reuse-code-and-images
If you do not want to do that, the easiest (as few changes as possible) way to achieve what you want, is to use
raise SystemExit
instead of
exit()
in your "batch" scripts
your main script then needs to catch this exception:
...
scripts = ["step1","step2","step3"]
for script in scripts:
scriptPath = os.path.join(Base_dir, script+".sikuli")
if not scriptPath in sys.path:
sys.path.append(scriptPath)
try:
execfile(os.path.join(scriptPath, script+".py"))
except SystemExit:
pass # do nothing in this case
...
all other exceptions will stop the main script
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.