Pig
  1. Pig
  2. PIG-2559

Embedded pig in python; invoking sys.exit(0) causes script failure

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.9.1, 0.10.0
    • Fix Version/s: 0.10.0, 0.11
    • Component/s: None
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      Description

      In embedded pig in python, if I have a sys.exit (0) the script always fails and returns exit code as 6.
      While it is agreeable that Pig will reinterpret the exit code from Python, sys.exit(0) should be considered as a normal termination.

      A sample code;

      #!/usr/bin/python
      from org.apache.pig.scripting import Pig
      import sys
      if 1 == 2:
              sys.exit(1)
      else:
              sys.exit(0)
      

      Exception from Pig

      org.apache.pig.backend.executionengine.ExecException: ERROR 1121: Python Error. Traceback (most recent call last):
        File "a.py", line 9, in <module>
          sys.exit(0)
      SystemExit: 0
      
      	at org.apache.pig.scripting.jython.JythonScriptEngine$Interpreter.execfile(JythonScriptEngine.java:107)
      	at org.apache.pig.scripting.jython.JythonScriptEngine.load(JythonScriptEngine.java:210)
      	at org.apache.pig.scripting.jython.JythonScriptEngine.main(JythonScriptEngine.java:202)
      	at org.apache.pig.scripting.ScriptEngine.run(ScriptEngine.java:275)
      	at org.apache.pig.Main.runEmbeddedScript(Main.java:925)
      	at org.apache.pig.Main.run(Main.java:516)
      	at org.apache.pig.Main.main(Main.java:111)
      Caused by: Traceback (most recent call last):
        File "a.py", line 9, in <module>
          sys.exit(0)
      SystemExit: 0
      
      	at org.python.core.PyException.fillInStackTrace(PyException.java:70)
      	at java.lang.Throwable.<init>(Throwable.java:181)
      	at java.lang.Exception.<init>(Exception.java:29)
      	at java.lang.RuntimeException.<init>(RuntimeException.java:32)
      	at org.python.core.PyException.<init>(PyException.java:46)
      	at org.python.core.PyException.<init>(PyException.java:43)
      	at org.python.core.PySystemState.exit(PySystemState.java:1206)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
      	at org.python.core.PyObject.__call__(PyObject.java:355)
      	at org.python.core.PyMethod.__call__(PyMethod.java:215)
      	at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
      	at org.python.core.PyMethod.__call__(PyMethod.java:206)
      	at org.python.core.PyObject.__call__(PyObject.java:397)
      	at org.python.core.PyObject.__call__(PyObject.java:401)
      	at org.python.pycode._pyx0.f$0(a.py:9)
      	at org.python.pycode._pyx0.call_function(a.py)
      	at org.python.core.PyTableCode.call(PyTableCode.java:165)
      	at org.python.core.PyCode.call(PyCode.java:18)
      	at org.python.core.Py.runCode(Py.java:1197)
      	at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:166)
      	at org.apache.pig.scripting.jython.JythonScriptEngine$Interpreter.execfile(JythonScriptEngine.java:104)
      	... 6 more
      
      1. PIG-2559_1.patch
        2 kB
        Vivek Padmanabhan

        Issue Links

          Activity

          Vivek Padmanabhan created issue -
          Hide
          Vivek Padmanabhan added a comment -

          I ran a test script with jython command line and there is no such exceptions happening.
          Looking further into jython source, I think PyException will be thrown in case of sys.exit is invoked. But it is handled further by org.python.core.Py.

          I believe Pig should also check the Exception thrown by python and not re-throw the exception if the exit code is set to 0.

          Show
          Vivek Padmanabhan added a comment - I ran a test script with jython command line and there is no such exceptions happening. Looking further into jython source, I think PyException will be thrown in case of sys.exit is invoked. But it is handled further by org.python.core.Py. I believe Pig should also check the Exception thrown by python and not re-throw the exception if the exit code is set to 0.
          Hide
          Vivek Padmanabhan added a comment -

          Attaching an initial patch

          Show
          Vivek Padmanabhan added a comment - Attaching an initial patch
          Vivek Padmanabhan made changes -
          Field Original Value New Value
          Attachment PIG-2559_1.patch [ 12516163 ]
          Vivek Padmanabhan made changes -
          Status Open [ 1 ] Patch Available [ 10002 ]
          Hide
          Daniel Dai added a comment -

          Patch looks good to me. Is there anything else you want to do since you mention it is "initial patch"?

          Show
          Daniel Dai added a comment - Patch looks good to me. Is there anything else you want to do since you mention it is "initial patch"?
          Daniel Dai made changes -
          Link This issue is related to PIG-2558 [ PIG-2558 ]
          Hide
          Vivek Padmanabhan added a comment -

          Nothing more, I was just anticipating any comments. test-commit was passing for this patch.

          Show
          Vivek Padmanabhan added a comment - Nothing more, I was just anticipating any comments. test-commit was passing for this patch.
          Hide
          Daniel Dai added a comment -

          Unit test pass. test-patch:
          [exec] -1 overall.
          [exec]
          [exec] +1 @author. The patch does not contain any @author tags.
          [exec]
          [exec] +1 tests included. The patch appears to include 3 new or modified tests.
          [exec]
          [exec] -1 javadoc. The javadoc tool appears to have generated 1 warning messages.
          [exec]
          [exec] +1 javac. The applied patch does not increase the total number of javac compiler warnings.
          [exec]
          [exec] +1 findbugs. The patch does not introduce any new Findbugs warnings.
          [exec]
          [exec] -1 release audit. The applied patch generated 533 release audit warnings (more than the trunk's current 530 warnings).

          javadoc and release audit warning is unrelated.

          Patch committed to 0.10/trunk. Thanks Vivek!

          Show
          Daniel Dai added a comment - Unit test pass. test-patch: [exec] -1 overall. [exec] [exec] +1 @author. The patch does not contain any @author tags. [exec] [exec] +1 tests included. The patch appears to include 3 new or modified tests. [exec] [exec] -1 javadoc. The javadoc tool appears to have generated 1 warning messages. [exec] [exec] +1 javac. The applied patch does not increase the total number of javac compiler warnings. [exec] [exec] +1 findbugs. The patch does not introduce any new Findbugs warnings. [exec] [exec] -1 release audit. The applied patch generated 533 release audit warnings (more than the trunk's current 530 warnings). javadoc and release audit warning is unrelated. Patch committed to 0.10/trunk. Thanks Vivek!
          Daniel Dai made changes -
          Status Patch Available [ 10002 ] Resolved [ 5 ]
          Hadoop Flags Reviewed [ 10343 ]
          Assignee Vivek Padmanabhan [ vivekp ]
          Fix Version/s 0.10 [ 12316246 ]
          Fix Version/s 0.11 [ 12318878 ]
          Resolution Fixed [ 1 ]
          Daniel Dai made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Vivek Padmanabhan
              Reporter:
              Vivek Padmanabhan
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development