using sys.exit(2) throws an exception --- defined Jython interpreter behavior --- use exit() instead

Asked by markshao

I try to stop the sikuli process with error exit code by call the api sys.exit(2).

But it throws an exception

     [exec] Traceback (most recent call last):
     [exec] File "C:\Users\user\Desktop\scripts_folder\deployment.sikuli\deployment.py", line 100, in <module>
     [exec] sys.exit(2)
     [exec] Sy

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
RaiMan (raimund-hocke) said :
#1

use exit(2)

Revision history for this message
RaiMan (raimund-hocke) said :
#2

what Sikuli version?

Revision history for this message
markshao (mark-shao) said :
#3

1.0.0-win32

Revision history for this message
markshao (mark-shao) said :
#4

The sys module is not supported inside the sikuli . My understand is that the sikuli contains an whole package of jython. could you tell me why? I am so interested about it .

Revision history for this message
RaiMan (raimund-hocke) said :
#5

The sys module is indeed supported.

But since we internally run the scripts using a jython interpreter instance from Java JVM, this is Jython defined behavior, so a sys.exit() in a script cannot shutdown the whole JVM.

Therefor we have exit().

BTW: already checked the new version 1.0.1?

Revision history for this message
markshao (mark-shao) said :
#6

We are still using the old version of sikuli , we plan to upgrade the sikuli to the latest version.

Currently we have established the CI environment and using the ANT to trigger the sikuli script . We hope to get the process exit code of the sikuli so that we can decide whether to move forward to the next Ant task.

I think you are right , because even though we try to call the sys.exit(2) inside the sikuli script , the ant still get the 0 exit code . I think this means the sys.exit(2) could not exit the JVM , so the JVM is exit normally.

I will modify the code and see the result later .

Thanks so much RaiMan.

Revision history for this message
markshao (mark-shao) said :
#7

Hey RaiMan

    I still get the exception when I execute the sikuli through ANT from jenkins.

The piece of the sikuli script is :

    if exists("1377257662744.png"):
        captureScreen()
        wait(5)
        click("1377257674028.png")
        App.close('xCP Designer')
        print 'Delopyment fail and get the error dialog'
        exit(2)

    # another error message
    if exists("1378691970944.png"):
        captureScreen()
        wait(2)
        click("1378691994428.png")
        App.close('xCP Designer')
        print 'The problems found when running the application'
        exit(3)

Now I directly using the exit() function other than the sys.exit()

I using ANT to trigger the sikuli script as following

<target name="deploy">
  <exec executable="cmd" dir="${env.USERPROFILE}/Desktop/Sikuli-IDE-1.0.0-Win32" failonerror="true" resultproperty="isGood">
      <arg line="/c sikuli-script -j6 -r ${env.USERPROFILE}\Desktop\scripts_folder\deployment.sikuli"/>
  </exec>
  <echo message="[Ant] The deployment process exit code is ${isGood}"/>
  <if>
   <equals arg1="${isGood}" arg2="0" />
   <then>
    <echo message="[Ant] The deployment action is ok"/>
   </then>
   <else>
    <fail>
     <echo message="[Ant] The deployment action fail"/>
    </fail>
   </else>
  </if>
 </target>

The field "isGood" is used to store the exit code of sikuli process , and the build.xml file is triggered by jenkins using ANT, but I found the some strange things in the console log of the jenkins

    [exec] Traceback (most recent call last):
     [exec] File "C:\Users\user\Desktop\scripts_folder\deployment.sikuli\deployment.py", line 103, in <module>
     [exec] exit(2)
     [exec] File "C:\Users\user\Desktop\Sikuli-IDE-1.0.0-Win32\sikuli-script.jar\Lib\sikuli\Sikuli.py", line 210, in exit
     [exec] sys.exit(code)
     [exec] SystemExit: 2
     [exec] [info] Exit code: 1
     [echo] [Ant] The deployment process exit code is 0
     [echo] [Ant] The deployment action is ok

First strange thing is that why the sikuli script throw the exception when call the exit(2) method . And the echo message from ant still get the 0 exit code . But before that It shows that the Exit code is 1 . But in fact I exit the process with the code 2.

Could you help give me some advices about it ? I hope I can get the exit 2 code from the outside process.

Thanks .

Revision history for this message
markshao (mark-shao) said :
#8

Wait for your help

Revision history for this message
RaiMan (raimund-hocke) said :
#9

I have to check in the code and have to debug.
takes a while. I will come back as soon as possible.

Revision history for this message
RaiMan (raimund-hocke) said :
#10

fixed with actual version of 1.0.1 --- see related bug

Revision history for this message
markshao (mark-shao) said :
#11

Thanks Raiman , I will upgrade to the latest version of sikuli and check the result

Can you help with this problem?

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

To post a message you must log in.