當前位置: 首頁>>代碼示例>>Java>>正文


Java PythonInterpreter.compile方法代碼示例

本文整理匯總了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;
}
 
開發者ID:glaudiston,項目名稱:project-bianca,代碼行數:24,代碼來源:Python.java

示例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();
}
 
開發者ID:kasemir,項目名稱:org.csstudio.display.builder,代碼行數:32,代碼來源:JythonTest.java

示例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());
    }
}
 
開發者ID:Talend,項目名稱:components,代碼行數:10,代碼來源:PythonRowDoFn.java

示例4: compile

import org.python.util.PythonInterpreter; //導入方法依賴的package包/類
private PyCode compile(PythonInterpreter interpreter, String statement) {
	return interpreter.compile(statement);
}
 
開發者ID:therelaxist,項目名稱:spring-usc,代碼行數:4,代碼來源:PythonRepository.java


注:本文中的org.python.util.PythonInterpreter.compile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。