本文整理汇总了Java中org.python.core.Py.setSystemState方法的典型用法代码示例。如果您正苦于以下问题:Java Py.setSystemState方法的具体用法?Java Py.setSystemState怎么用?Java Py.setSystemState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.Py
的用法示例。
在下文中一共展示了Py.setSystemState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupSystemState
import org.python.core.Py; //导入方法依赖的package包/类
/**
* Call to ensure that an interpreter is set up and configured and
* able to load the relevant bundles.
*/
public static synchronized void setupSystemState(String... bundleNames) {
ClassLoader loader=null;
if (configuredState==null) { // Relies on setupSystemState() being called early in the server startup.
loader = createJythonClassLoader(PySystemState.class.getClassLoader());
initializePythonPath(loader);
}
PySystemState state = Py.getSystemState();
if (state==configuredState) return;
if (loader==null) {
// Then someone else has changed the PySystemState
// They will not have added our
loader = createJythonClassLoader(state.getClassLoader()); // Don't clobber their working.
}
state.setClassLoader(loader);
setJythonPaths(state); // Tries to ensure that enough of jython is on the path
setSpgGeneratorPaths(state, bundleNames); // Adds the scripts directory from points
Py.setSystemState(state);
configuredState = state;
}
示例2: enter
import org.python.core.Py; //导入方法依赖的package包/类
@Override
public Object enter( String entryPointName, Executable executable, ExecutionContext executionContext, Object... arguments ) throws NoSuchMethodException, ParsingException, ExecutionException
{
entryPointName = toPythonStyle( entryPointName );
PythonInterpreter pythonInterpreter = (PythonInterpreter) executionContext.getAttributes().get( JYTHON_INTERPRETER );
Py.setSystemState( pythonInterpreter.getSystemState() );
PyObject method = pythonInterpreter.get( entryPointName );
if( method == null )
throw new NoSuchMethodException( entryPointName );
try
{
PyObject[] pythonArguments = Py.javas2pys( arguments );
PyObject r = method.__call__( pythonArguments );
return r.__tojava__( Object.class );
}
catch( Exception x )
{
throw JythonAdapter.createExecutionException( executable.getDocumentName(), 0, x );
}
finally
{
flush( pythonInterpreter, executionContext );
}
}
示例3: setPythonPath
import org.python.core.Py; //导入方法依赖的package包/类
private void setPythonPath(Engine engine) {
if (engine != null) {
String pythonPath = engine.getConfigurationManager().getProperty(PROP_PYTHON_PATH);
if (pythonPath != null) {
PySystemState engineSys = new PySystemState();
List<String> paths = Arrays.asList(StringUtils.split(pythonPath, PROP_PATH_SEPARATOR));
Collections.reverse(paths);
for (String pathElement : paths) {
engineSys.path.add(0, Py.newString(pathElement));
}
Py.setSystemState(engineSys);
}
}
}