本文整理汇总了Java中org.python.util.PythonInterpreter.compile方法的典型用法代码示例。如果您正苦于以下问题:Java PythonInterpreter.compile方法的具体用法?Java PythonInterpreter.compile怎么用?Java PythonInterpreter.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.util.PythonInterpreter
的用法示例。
在下文中一共展示了PythonInterpreter.compile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompiledMethod
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
/**
* Get a compiled version of the python call.
*
* @param name
* @param code
* @param interp
* @return
*/
private static synchronized PyObject getCompiledMethod(String name, String code, PythonInterpreter interp) {
// TODO change this from a synchronized method to a few blocks to
// improve concurrent performance
if (objectCache.containsKey(name)) {
return objectCache.get(name);
}
PyObject compiled = interp.compile(code);
if (objectCache.size() > 25) {
// keep the size to 6
objectCache.remove(objectCache.keySet().iterator().next());
}
objectCache.put(name, compiled);
return compiled;
}
示例2: testInterpreter
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
private void testInterpreter(final PythonInterpreter python) throws Exception
{
// Run on new threads to get fresh thread-locals
final ExecutorService new_executor = Executors.newCachedThreadPool();
final String script = "import sys\nresult = sys.path";
final Callable<String> test_run = () ->
{
// System.out.println("Executing on " + Thread.currentThread().getName());
final PyCode code = python.compile(script);
python.exec(code);
return python.get("result").toString();
};
final List<Future<String>> futures = new ArrayList<>();
final long end = System.currentTimeMillis() + 1000L;
while (System.currentTimeMillis() < end)
{
for (int i=0; i<50; ++i)
futures.add(new_executor.submit(test_run));
for (Future<String> future : futures)
{
final String result = future.get();
//System.out.println(result);
assertThat(result, containsString("always"));
assertThat(result, containsString("special"));
}
futures.clear();
}
new_executor.shutdown();
}
示例3: setup
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
@Setup
public void setup() throws Exception {
interpretor = new PythonInterpreter();
if (MapType.MAP.equals(properties.mapType.getValue())) {
pythonFunction = interpretor.compile(setUpMap());
} else { // flatmap
pythonFunction = interpretor.compile(setUpFlatMap());
}
}
示例4: compile
import org.python.util.PythonInterpreter; //导入方法依赖的package包/类
private PyCode compile(PythonInterpreter interpreter, String statement) {
return interpreter.compile(statement);
}