1.1 errors on attempting exit()

Asked by Erich Fiederer

Hi Raiman,

I've been developing a unit test environment on OSX with SikulixIDE 1.1.0, currently on 2015-05-13 nightly build.

I want to get some sort of return from my scripts, so that I can know if they are successful or not. It would seem that putting exit(1) or some other number would be the apropriate function.

However, while trying to import a file that has exit(1) at the end of the sikuli script, I get an error. Here is an example of one of the sikuli files I am trying to import:

from sikuli import *
click("1431123550795.png")
click("Screen Shot 2015-04-28 at 11.50.04 AM.png")
click("1418422585290.png")
click("1418422597111.png")
wait(3)
click("1418422611695.png")
wait(5)
click("1418422621054.png")
exit(1)

Here is the error while trying to import this file:

[error] script [ mytest ] stopped with error in line 2
[error] SystemExit ( !!WHILE IMPORTING!! 1 )
[error] --- Traceback --- error source first
line: module ( function ) statement
434: Sikuli ( exit ) SystemExit: !!WHILE IMPORTING!! 1
10: SFR_basic ( <module> ) exit(1)
[error] --- Traceback --- end --------------

What might I be doing wrong here? Is there a better function I should be using?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

what you are doing, is not really the intended use of import.

A script, intended to be imported should consist of at least some functions, that can be called by the importing script using

retval = module.function()

if the function ends with a
return number

then you will have that in your main script in retval then.

To change your code do the following:

# the sub module (e.g. mySubModule.sikuli)
from sikuli import *
def run():
    click("1431123550795.png")
    click("Screen Shot 2015-04-28 at 11.50.04 AM.png")
    click("1418422585290.png")
    click("1418422597111.png")
    wait(3)
    click("1418422611695.png")
    wait(5)
    click("1418422621054.png")
    return 1

and in the main module you have
import mySubModule
# … some code
retval = mySubModule.run()

This is the way how one should use the import.

Be aware: the code you currently have in your sub script is only executed once in a Sikuli session at time of import (indent-level-0-code)

With the "real" import solution, at time of import only the function is accepted as defined and nothing else happens.
the code in the function run is executed each time you use
mySubModule.run()

But if you want to stay with your solution of indent-level-0-code, then you have another option now (use the latest build please):
 http://sikulix-2014.readthedocs.org/en/latest/scripting.html#running-scripts-and-snippets-from-within-other-scripts-and-run-scripts-one-after-the-other

Revision history for this message
Erich Fiederer (erichfiederer) said :
#2

Vielen dank for the detailed response raiman!!

Revision history for this message
Erich Fiederer (erichfiederer) said :
#3

Thanks RaiMan, that solved my question.