org.python.util.PythonInterpreter.threadLocalStateInterpreter()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.python.util.PythonInterpreter.threadLocalStateInterpreter()方法的一些代码示例,展示了PythonInterpreter.threadLocalStateInterpreter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。PythonInterpreter.threadLocalStateInterpreter()方法的具体详情如下:
包路径:org.python.util.PythonInterpreter
类名称:PythonInterpreter
方法名:threadLocalStateInterpreter

PythonInterpreter.threadLocalStateInterpreter介绍

[英]Creates a new interpreter with the ability to maintain a separate local namespace for each thread (set by invoking setLocals()).
[中]创建一个新的解释器,该解释器能够为每个线程维护一个单独的本地名称空间(通过调用setLocals()进行设置)。

代码示例

代码示例来源:origin: org.python/jython

PyScriptEngine(ScriptEngineFactory factory) {
  this.factory = factory;
  interp = PythonInterpreter.threadLocalStateInterpreter(new PyScriptEngineScope(this, context));
}

代码示例来源:origin: langurmonkey/gaiasky

/**
 * Only initialize the executor service and the interpreter.
 */
private JythonFactory() {
  //	executor = Executors.newCachedThreadPool(new JythonThreadFactory());
  interpreter = PythonInterpreter.threadLocalStateInterpreter(null);
  currentScripts = Collections.synchronizedMap(new LinkedHashMap<String, ScriptRunnable>() {
    @Override
    public ScriptRunnable put(String key, ScriptRunnable value) {
      ScriptRunnable sr = super.put(key, value);
      EventManager.instance.post(Events.NUM_RUNNING_SCRIPTS, this.size());
      return sr;
    }
    @Override
    public ScriptRunnable remove(Object key) {
      ScriptRunnable sr = super.remove(key);
      EventManager.instance.post(Events.NUM_RUNNING_SCRIPTS, this.size());
      return sr;
    }
  });
  EventManager.instance.subscribe(this, Events.RUN_SCRIPT_PYCODE, Events.RUN_SCRIPT_PATH, Events.CANCEL_SCRIPT_CMD);
}

代码示例来源:origin: com.googlecode.the-fascinator/fascinator-core

python = PythonInterpreter.threadLocalStateInterpreter(null);
  python.execfile(inStream, "scriptname");
} catch (Exception ex) {

代码示例来源:origin: langurmonkey/gaiasky

@Override
public void run() {
  if (currentScripts.size() < maxScripts) {
    if (currentScripts.containsKey(path)) {
      logger.info(I18n.bundle.format("notif.script.already", path));
      return;
    }
    currentScripts.put(path, this);
    try {
      interpreter = PythonInterpreter.threadLocalStateInterpreter(null);
      interpreter.exec(code);
      cleanup();
    } catch (Exception e) {
      if (e.getCause() instanceof ThreadDeath) {
        logger.info("Script stopped");
      } else {
        logger.error(e);
      }
    }
  }
}

代码示例来源:origin: usc-isi-i2/Web-Karma

private void initialize()
{
  scripts = new ConcurrentHashMap<>();
  initialLocals = new PyStringMap();
  interpreter = PythonInterpreter.threadLocalStateInterpreter(initialLocals);
  
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getImportStatements());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getRowIndexDefStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getGetValueDefStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getGetValueFromNestedColumnByIndexDefStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getIsEmptyDefStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getHasSelectedRowsStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getVDefStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getTransformStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getSelectionStatement());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getModelName());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getModelPrefix());
  compileAndAddToRepository(interpreter, PythonTransformationHelper.getModelBaseUri());
  initializeInterpreter(interpreter);
}

相关文章