本文整理汇总了Java中org.python.util.PythonInterpreter.cleanup方法的典型用法代码示例。如果您正苦于以下问题:Java PythonInterpreter.cleanup方法的具体用法?Java PythonInterpreter.cleanup怎么用?Java PythonInterpreter.cleanup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.util.PythonInterpreter
的用法示例。
在下文中一共展示了PythonInterpreter.cleanup方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CreateFromPython
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
public void CreateFromPython()
{
PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState());
PySystemState sys = Py.getSystemState();
sys.path.append(new PyString(context.settings.GetModelPath()));
if(context.settings.GetSysPath() != null)
sys.path.append(new PyString(context.settings.GetSysPath()));
/*
// some magic to pass context to all python modules
interpreter.set("context", context);
interpreter.set("model_service", model_service);
interpreter.exec("import __builtin__");
interpreter.exec("__builtin__.context = context");
interpreter.exec("__builtin__.model_service = model_service");*/
interpreter.execfile(context.settings.GetModelPath() + '/' + context.settings.GetModelMain());
interpreter.cleanup();
UpdateDefinedSensors();
}
示例2: runCxxTestGen
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
private void runCxxTestGen( String testTarget, List<String> arguments ) throws MojoExecutionException
{
final String cxxTestGenArgVar = "cxxTestGenArgs";
String cxxTestGenPath = cxxTest.getCxxTestHome().getAbsolutePath();
PyList cxxTestGenArgs = new PyList( arguments );
cxxTestGenArgs.add( 0, cxxTestGenPath );
getLog().info( "Executing test runner generation for target " + testTarget + "." );
getLog().debug( "Executing Python script " + cxxTestGenPath + " with arguments=" + cxxTestGenArgs );
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec( "import cxxtest" );
resetCxxTestSuites( pythonInterpreter );
pythonInterpreter.set( cxxTestGenArgVar, cxxTestGenArgs );
pythonInterpreter.exec( "cxxtest.main(" + cxxTestGenArgVar + ")" );
pythonInterpreter.cleanup();
getLog().info( "Test runner generation for target " + testTarget + " succeeded." );
}
示例3: loadFromFile
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
* Loads a module from a Python file that contains a class with the <b>SAME</b> name as the file.
* The class must extend {@link ExternalModule}.
*
* @param f the file to load the {@link org.freecode.irc.votebot.api.ExternalModule} from
* @return the {@link ExternalModule} loaded, or <tt>null</tt>
* @throws IOException if the file was not found
* @throws ScriptException if the script failed to load
*/
public ExternalModule loadFromFile(final File f) throws IOException, ScriptException {
if (f == null || !f.exists()) {
throw new IOException("Invalid file");
}
if (f.getName().endsWith(".py")) {
PythonInterpreter interpreter = new PythonInterpreter();
String clzName = f.getName().replace(".py", "");
interpreter.exec(String.format("from %s import %s", clzName, clzName));
PyObject pyClass = interpreter.get(clzName);
PyObject buildObject = pyClass.__call__();
ExternalModule ext = (ExternalModule) buildObject.__tojava__(ExternalModule.class);
ext.setFvb(fvb);
ext.setExtName(clzName);
interpreter.cleanup();
return ext;
}
return null;
}
示例4: recompile
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
@Override
public boolean recompile(boolean reload) {
if(reload){
this.setScript(this.extractFile());
}
PythonInterpreter python = new PythonInterpreter();
this.setCompiled(python.compile(this.getScript()));
python.cleanup();
return true;
}
示例5: buildPythonInterpreter
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
public static PythonInterpreter buildPythonInterpreter(PyObject dist, boolean cleanup) {
PythonInterpreter pyInterpreter = PythonInterpreter.threadLocalStateInterpreter(dist);
if (cleanup) {
pyInterpreter.cleanup();
}
return pyInterpreter;
}
示例6: getMethod
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
private static PyObject getMethod(String path, String module, String method) { // Ziggy: This could probably be moved to callScript()
PythonInterpreter python = new PythonInterpreter(); // since it's not used elsewhere.
python.cleanup();
python.execfile(path + module + ".py");
return python.get(method);
}
示例7: callScript
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
public void callScript(String path, String module, String method) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys\nsys.path.append('" + path + "')\nfrom " + module + " import " + method);
PyObject func = interpreter.get(method);
func.__call__(Py.java2py(core));
interpreter.cleanup();
}