[kepler-dev] PythonScript actor throws exception in PN at the end

Christopher Brooks cxh at eecs.berkeley.edu
Fri May 23 13:26:11 PDT 2008


Hi Norbert,

Thanks for the patch, I lead me down the path to a more robust
workaround.


For those on kepler-dev:
   To replicate the problem, run actor/lib/python/test/auto/PythonScalePN.xml
   At the end a stack trace appears.

I took a look and modified PythonScript.java so that it now catches
the inner TerminateProcessException and then rethrows it.

I did this by using the PyException object.

To get to this point, I had to compile Jython with debugging turned on.

1) Download Jython-2.2.1 and install with sources
2) Compile Jython.  To do this I had to edit c:/Jython-2.2.1/build.xml
   and make two changes.
   1.  Change
     <property name="debug" value="off" />
     to
     <property name="debug" value="on" />
   
   2.  Change
     <property name="source.dir" value="${basedir}/src/" />
     to
     <property name="source.dir" value="${basedir}/src/java/src" />
3) I then ran
     cd c:/jython-2.2.1
     ant
   Note that errors occurred, but that was ok.

4) Move the previous jython.jar files:
   mv $PTII/lib/jython.jar $PTII/lib/jython.jar-old
   mv $PTII/vendors/jython/jython.jar $PTII/vendors/jython/jython.jar-old

5) Set the path
   export CLASSPATH=c:/jython2.2.1/build

6) Run the demo with
   $PTII/bin/vergil
   ptolemy/actor/lib/jython/test/auto/PythonScalePN.xml

This will give a stack trace with the line numbers included.

My change to PythonScript is below.  I've checked this change 
into the ptII tree:
                    try {
                        returnValue = method.__call__();
                    } catch (Exception ex) {
                        // If the inner exception is TerminateProcessException,
                        // then get the exception and rethrow it.
                        if (ex instanceof PyException) {
                            PyException pyException = (PyException)ex;
                            Exception innerException = (Exception)pyException.value.__tojava__(Exception.class);
                            if (innerException instanceof TerminateProcessException) {
                                // Work around bug reported by
                                // Norbert Podhorszki
                                // See python/test/auto/PythonScalePN.xml
                                throw (TerminateProcessException) innerException;
                            } else {
                                throw ex;
                            }
                        } else {
                            throw ex;
                        }
                    }

_Christopher
--------
    
    Hi Christopher,
    
    Here I just modified the kepler/demos/Python/PythonScale workflow, replacin
   g
    SDF with PN Director and put the firing limit into Ramp instead of into the
    director. line 7 in the python actor is the input.get(0).
    
    I do not have jython installed. I am trying to use the python actor as is
    first. It sucks though, because I needed the re module; instead I had to
    program with java Pattern and Matcher.
    
    I tried to look for the TerminateProcessException in the
    ptolemy.actor.lib.python.PythonScript._invokeMethod() but failed to catch i
   t
    there; it must be already packed into something else.
    
    Norbert
    
    
    On 5/6/08 5:39 PM, "Christopher Brooks" <cxh at eecs.berkeley.edu> wrote:
    
    > Hi Norbert,
    > Do you have a test case?
    > 
    > Also, try rebuilding jython so that the stack trace has the line
    > numbers.
    > I'm assuming we are all using Jython-2.2.1, right?
    > 
    > My guess is that Jython is invoking a separate thread?
    > 
    > 
    > _Christopher
    > --------
    > 
    >> This message is in MIME format. Since your mail reader does not understa
   n
    >    d
    >     this format, some or all of this message may not be legible.
    >     
    >     --Boundary_(ID_D8T0hfIyhaIR+LLjdl7u6A)
    >     Content-type: text/plain; charset="US-ASCII"
    >     Content-transfer-encoding: 7bit
    >     
    >     Hi Christopher and Dan,
    >     
    >     I am trying to use the python actor. I realized that if I use it unde
   r PN,
    >     an exception is thrown when the PN Director tries to stop all actors 
   at
    > the
    >     end of the workflow run. Actors are waiting in a <port>.get() call at
    such
    >    a
    >     moment. The python actor does not like the idea of being stopped.
    >     
    >     Do you have a quick fix for this problem or should we put this into
    >     bugzilla?
    >     I suspect that ptolemy.actor.lib.python.PythonScript._invokeMethod() 
   could
    >     catch the exception and swallow it but I am not sure how this actor w
   orks.
    >     
    >     Norbert
    >     
    >     Here is the trace:
    >     
    >     ptolemy.kernel.util.IllegalActionException: Error in invoking the fir
   e
    >     method:
    >     line 7, in fire
    >         at 
    >     ptolemy.domains.pn.kernel.PNQueueReceiver.get(PNQueueReceiver.java:18
   5)
    >         at ptolemy.actor.IOPort.get(IOPort.java:783)
    >         at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
    >         at 
    >     
    > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
   mp
    >    l
    >     .java:25)
    >         at java.lang.reflect.Method.invoke(Method.java:585)
    >     
    >     ptolemy.actor.process.TerminateProcessException:
    >     ptolemy.actor.process.TerminateProcessException:
    >     
    >       in .PythonScale.PythonActor
    >     Because:
    >     Traceback (innermost last):
    >       File "<string>", line 7, in fire
    >         at 
    >     ptolemy.domains.pn.kernel.PNQueueReceiver.get(PNQueueReceiver.java:18
   5)
    >         at ptolemy.actor.IOPort.get(IOPort.java:783)
    >         at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
    >         at 
    >     
    > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
   mp
    >    l
    >     .java:25)
    >         at java.lang.reflect.Method.invoke(Method.java:585)
    >     
    >     ptolemy.actor.process.TerminateProcessException:
    >     ptolemy.actor.process.TerminateProcessException:
    >     
    >         at 
    >     
    > ptolemy.actor.lib.python.PythonScript._reportScriptError(PythonScript.jav
   a:
    >    5
    >     50)
    >         at 
    >     ptolemy.actor.lib.python.PythonScript._invokeMethod(PythonScript.java
   :506)
    >         at ptolemy.actor.lib.python.PythonScript.fire(PythonScript.java:2
   36)
    >         at ptolemy.actor.process.ProcessThread.run(ProcessThread.java:199
   )
    >     Caused by: Traceback (innermost last):
    >       File "<string>", line 7, in fire
    >         at 
    >     ptolemy.domains.pn.kernel.PNQueueReceiver.get(PNQueueReceiver.java:18
   5)
    >         at ptolemy.actor.IOPort.get(IOPort.java:783)
    >         at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
    >         at 
    >     
    > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
   mp
    >    l
    >     .java:25)
    >         at java.lang.reflect.Method.invoke(Method.java:585)
    >     
    >     ptolemy.actor.process.TerminateProcessException:
    >     ptolemy.actor.process.TerminateProcessException:
    >     
    >         at org.python.core.Py.JavaError(Unknown Source)
    >         at org.python.core.Py.JavaError(Unknown Source)
    >         at org.python.core.PyReflectedFunction.__call__(Unknown Source)
    >         at org.python.core.PyMethod.__call__(Unknown Source)
    >         at org.python.core.PyObject.__call__(Unknown Source)
    >         at org.python.core.PyInstance.invoke(Unknown Source)
    >         at org.python.pycode._pyx8.fire$2(<string>:7)
    >         at org.python.pycode._pyx8.call_function(<string>)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyFunction.__call__(Unknown Source)
    >         at org.python.core.PyMethod.__call__(Unknown Source)
    >         at org.python.core.PyObject.__call__(Unknown Source)
    >         at 
    >     ptolemy.actor.lib.python.PythonScript._invokeMethod(PythonScript.java
   :487)
    >         ... 2 more
    >     Caused by: Traceback (innermost last):
    >       File "<string>", line 7, in fire
    >         at 
    >     ptolemy.domains.pn.kernel.PNQueueReceiver.get(PNQueueReceiver.java:18
   5)
    >         at ptolemy.actor.IOPort.get(IOPort.java:783)
    >         at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
    >         at 
    >     
    > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorI
   mp
    >    l
    >     .java:25)
    >         at java.lang.reflect.Method.invoke(Method.java:585)
    >     
    >     ptolemy.actor.process.TerminateProcessException:
    >     ptolemy.actor.process.TerminateProcessException:
    >     
    >         at org.python.core.Py.JavaError(Unknown Source)
    >         at org.python.core.Py.JavaError(Unknown Source)
    >         at org.python.core.PyReflectedFunction.__call__(Unknown Source)
    >         at org.python.core.PyMethod.__call__(Unknown Source)
    >         at org.python.core.PyObject.__call__(Unknown Source)
    >         at org.python.core.PyInstance.invoke(Unknown Source)
    >         at org.python.pycode._pyx8.fire$2(<string>:7)
    >         at org.python.pycode._pyx8.call_function(<string>)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyTableCode.call(Unknown Source)
    >         at org.python.core.PyFunction.__call__(Unknown Source)
    >         at org.python.core.PyMethod.__call__(Unknown Source)
    >         at org.python.core.PyObject.__call__(Unknown Source)
    >         at 
    >     ptolemy.actor.lib.python.PythonScript._invokeMethod(PythonScript.java
   :487)
    >         at ptolemy.actor.lib.python.PythonScript.fire(PythonScript.java:2
   36)
    >         at ptolemy.actor.process.ProcessThread.run(ProcessThread.java:199
   )


More information about the Kepler-dev mailing list