Jython @ScriptService issue

Hi guys,

I’m trying something actually quite simple. I would like to call one jython script from another inside Fiji.

This is the “outer script”:

#@ScriptService scriptService

from java.util import HashMap

parameterMap = HashMap()
parameterMap.put("var", "world")

scriptService.run("test.py", None, parameterMap)

And this is the “inner script”:

#@String var
print("Hello " + var)

When I run the outer script, I get this error message:

Started scriptServiceTest.py at Fri Dec 16 15:32:16 CET 2016
Traceback (most recent call last):
  File "/Users/rhaase/code/scriptServiceTest.py", line 9, in <module>
    scriptService.run("test.py", None, parameterMap)
TypeError: run(): 3rd arg can't be coerced to java.util.Map, java.lang.Object[]

	at org.python.core.Py.TypeError(Py.java:235)
	at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:209)
	at org.python.core.PyReflectedFunction.throwBadArgError(PyReflectedFunction.java:312)
	at org.python.core.PyReflectedFunction.throwError(PyReflectedFunction.java:321)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:167)
	at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
	at org.python.core.PyObject.__call__(PyObject.java:441)
	at org.python.core.PyObject.__call__(PyObject.java:447)
	at org.python.core.PyMethod.__call__(PyMethod.java:154)
	at org.python.pycode._pyx18.f$0(/Users/rhaase/code/scriptServiceTest.py:9)
	at org.python.pycode._pyx18.call_function(/Users/rhaase/code/scriptServiceTest.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:1275)
	at org.scijava.plugins.scripting.jython.JythonScriptEngine.eval(JythonScriptEngine.java:76)
	at org.scijava.script.ScriptModule.run(ScriptModule.java:177)
	at org.scijava.module.ModuleRunner.run(ModuleRunner.java:167)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)
	at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)
	at org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

I don’t get it. I also had issues with the “None” in the same line. It actually expects a boolean, but when I enter “True”, it says TypeError: run(): 2nd arg can't be coerced to boolean which is somehow the same error. And if True is no boolean - what is it then? :wink:

Did anyone have similar experience?


There is a Java signature confusion. If you pass a String, it is excepted to be source code and not a filename. To pass a filename you need to pass a java File object. The following works :

#@ScriptService scriptService

from java.io import File

parameterMap = {}
parameterMap["var"] = "world"

scriptService.run(File("test.py"), True, parameterMap)

@hadim thanks for your helpful hint. However, it did not run in my case. So far I found out: It needs to be an absolute path to make Fiji find the test.py file. And furthermore: it does not hand over the parameter.

When I run this code:

#@ScriptService scriptService

from java.util import HashMap
from java.io import File

parameterMap = {}
parameterMap["var"] = "world"

scriptService.run(File ("/Users/rhaase/temp/test.py"), True, parameterMap)

… a dialog opens asking me for “var”. Furthermore, the console pops up with the error message

[ERROR] Ignoring extraneous argument: {'var': 'world'}

Does anyone know what that means?


I am away from the computer from now so it’s hard to reproduce but from what I see it ‘should’ work. Try to replace your dict parameters by a Java HashMap as in your first script.

Thanks for answering again so quickly. I tried that earlier (see code above) and it didn’t work as well. The error message in this case is:

[ERROR] Ignoring extraneous argument: {var=world}

Actually, I thought “calling one script from another” or “plugins calling scripts” or “scripts calling plugins” is something that should work as easy as possible using the @ Parameter stuff. But already in this simple case, it appears buggy… :frowning:

For anyone who happens across this thread: @haesleinhuepf has now filed an issue—scijava/scripting-jython#8—to track this problem. I will respond there.