use of org.python.core.PyException in project oxCore by GluuFederation.
the class PythonService method initPythonInterpreter.
/*
* Initialize singleton instance during startup
*/
public boolean initPythonInterpreter(String pythonModulesDir) {
boolean result = false;
if (isInitInterpreter()) {
try {
PythonInterpreter.initialize(getPreProperties(), getPostProperties(pythonModulesDir), null);
this.pythonInterpreter = new PythonInterpreter();
// Init output redirect for all new interpreters
this.pythonInterpreter.setOut(new PythonLoggerOutputStream(log, false));
this.pythonInterpreter.setErr(new PythonLoggerOutputStream(log, true));
result = true;
} catch (PyException ex) {
log.error("Failed to initialize PythonInterpreter correctly", ex);
} catch (Exception ex) {
log.error("Failed to initialize PythonInterpreter correctly", ex);
}
}
this.interpereterReady = result;
return result;
}
use of org.python.core.PyException in project scriptographer by scriptographer.
the class JythonCallable method call.
public Object call(Object obj, Object[] args) throws JythonException {
// function on it.
try {
PyObject[] wrappedArgs = new PyObject[args == null ? 1 : args.length + 1];
// self
wrappedArgs[0] = Py.java2py(obj);
// args
for (int i = 1; i < wrappedArgs.length; i++) wrappedArgs[i] = Py.java2py(args[i - 1]);
PyObject ret = function.__call__(wrappedArgs);
// unwrap if the return value is a native java object:
Object res = ret.__tojava__(Object.class);
return res != Py.NoConversion ? res : ret;
} catch (PyException e) {
throw new JythonException(e);
}
}
Aggregations