Issue1663
Created on 2010-10-04.08:32:46 by spider, last changed 2010-10-15.14:01:15 by zyasoft.
Messages | |||
---|---|---|---|
msg6132 (view) | Author: Matthew Webber (spider) | Date: 2010-10-04.08:32:43 | |
Our code uses a displayhook (see www.python.org/dev/peps/pep-0217/). It works in Jython 2.5.1, but fails in 2.5.1rc1 and 2.5.2rc2 with the following traceback: 2010-10-01 10:36:26,318 WARN [gda.jython.GDAInteractiveConsole] - InteractiveConsole exception: Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: displayhook(): expected 1 args; got 0 org.python.core.PyException at org.python.core.PyException.fillInStackTrace(PyException.java:70) [jython.jar:na] at java.lang.Throwable.<init>(Throwable.java:181) [na:1.6.0_16] at java.lang.Exception.<init>(Exception.java:29) [na:1.6.0_16] at java.lang.RuntimeException.<init>(RuntimeException.java:32) [na:1.6.0_16] at org.python.core.PyException.<init>(PyException.java:46) [jython.jar:na] at org.python.core.PyException.<init>(PyException.java:43) [jython.jar:na] at org.python.core.PyException.<init>(PyException.java:61) [jython.jar:na] at org.python.core.Py.TypeError(Py.java:221) [jython.jar:na] at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209) [jython.jar:na] at org.python.core.PyReflectedFunction.throwArgCountError(PyReflectedFunction.java:262) [jython.jar:na] at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:319) [jython.jar:na] at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:167) [jython.jar:na] at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204) [jython.jar:na] at org.python.core.PyObject.__call__(PyObject.java:387) [jython.jar:na] at org.python.core.PyObject.invoke(PyObject.java:3585) [jython.jar:na] at org.python.core.Py.printResult(Py.java:1792) [jython.jar:na] at org.python.pycode._pyx69.f$0(<input>:1) [na:na] at org.python.pycode._pyx69.call_function(<input>) [na:na] at org.python.core.PyTableCode.call(PyTableCode.java:165) [jython.jar:na] at org.python.core.PyCode.call(PyCode.java:18) [jython.jar:na] at org.python.core.Py.runCode(Py.java:1253) [jython.jar:na] at org.python.core.Py.exec(Py.java:1297) [jython.jar:na] at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215) [jython.jar:na] at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89) [jython.jar:na] at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70) [jython.jar:na] at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:42) [jython.jar:na] at gda.jython.GDAJythonInterpreter.populateNamespace(GDAJythonInterpreter.java:493) [main/:na] at gda.jython.GDAJythonInterpreter.initialise(GDAJythonInterpreter.java:463) [main/:na] at gda.jython.JythonServer.configure(JythonServer.java:338) [main/:na] at gda.factory.FactoryBase.configure(FactoryBase.java:64) [main/:na] at gda.util.ObjectCreatorsObjectServer.startServer(ObjectCreatorsObjectServer.java:288) [main/:na] at gda.util.ObjectServer.configure(ObjectServer.java:335) [main/:na] at gda.util.ObjectServer.createServerImpl(ObjectServer.java:133) [main/:na] at gda.util.ObjectServer.main(ObjectServer.java:503) [main/:na] 2010-10-01 10:36:26,424 WARN [gda.jython.GDAInteractiveConsole] - InteractiveConsole exception: Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: displayhook(): expected 1 args; got 0 displayhook itself is fairly simple: public static void displayhook(PyObject o) { /* Print value except if None */ /* After printing, also assign to '_' */ /* Before, set '_' to None to avoid recursion */ if (o == Py.None) return; PyObject currentBuiltins = Py.getSystemState().getBuiltins(); currentBuiltins.__setitem__("_", Py.None); if (o instanceof PyUnicode) { PyUnicode u = (PyUnicode)o; Py.println(u.__str__()); } else { Py.println(o.__repr__()); } currentBuiltins.__setitem__("_", o); } Unfortunately this is part of a fairly large code base, and at this point I haven't pulled out a simple test case for you. A quick glance at the change log doesn't throw up any obvious candidates. |
|||
msg6133 (view) | Author: Matthew Webber (spider) | Date: 2010-10-04.08:48:16 | |
Correction to above: OLD: fails in 2.5.1rc1 and 2.5.2rc2 NEW: fails in 2.5.2rc1 and 2.5.2rc2 |
|||
msg6134 (view) | Author: Matthew Webber (spider) | Date: 2010-10-04.10:51:50 | |
OK, I think we've found where the problem was introduced: Revision 6837 hack around PyReflectedFunction's assumption of how instancemethod calls into it so instancemethod's ThreadState pass through optimization can be enabled The problem is in PyReflectedFunction.java, in this method: public PyObject __call__(PyObject[] args, String[] keywords) { (it's line 194 in revision 7066). I don't have enough understanding of how all this fits together to suggest a fix (the comment in line 48 // NOTE: this calledStatically business is pretty hacky suggests only the brave should touch this code). However, I hope that's enough to get you started. |
|||
msg6168 (view) | Author: Jim Baker (zyasoft) | Date: 2010-10-15.14:01:13 | |
I can't reproduce this problem on Jython trunk. Here's what I tried: >>> import dh >>> import sys >>> h = dh() >>> h.hook("hi") Hooked<<<hi>>> >>> sys.displayhook = h.hook >>> "foo" Hooked<<<foo>>> >>> sys.displayhook = dh.static_hook >>> "foo" Hooked<<<foo>>> This is the dh class: import org.python.core.PyObject; public class dh { public dh() {} public static void static_hook(PyObject o) { System.out.println("Hooked<<<" + o + ">>>"); } public void hook(PyObject o) { System.out.println("Hooked<<<" + o + ">>>"); } } So that all looks good to me. Please submit a test case (in either JUnit or PyUnit, see our test cases for examples) and reopen if you're still experiencing a problem. I did take a look at the possibility of downloading and running GDA, but that's just too big of a project. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-15 14:01:15 | zyasoft | set | status: open -> closed resolution: works for me messages: + msg6168 |
2010-10-06 04:22:31 | zyasoft | set | priority: high assignee: zyasoft nosy: + zyasoft |
2010-10-04 10:51:51 | spider | set | messages: + msg6134 |
2010-10-04 08:48:16 | spider | set | messages: + msg6133 |
2010-10-04 08:32:46 | spider | create |
Supported by Python Software Foundation,
Powered by Roundup