Exemplo n.º 1
0
  private void listen(int portNumber) throws IOException {
    Socket s;
    Thread t;

    PySystemState.initialize();

    try {
      sock = new ServerSocket(portNumber);
    } catch (IOException e) {
      System.err.println("Could not listen on port: 4444.");
      return;
    }

    while (true) {
      s = sock.accept();

      synchronized (lock) {
        if (shutdownRequested) {
          break;
        }
      }

      t = new JythonServerWorker(s, new JythonServerProtocol(s));
      t.start();
    }

    sock.close();
  }
  @Test
  public void testCreateInstrumentedProxy() throws Exception {
    final GrinderProperties properties = new GrinderProperties();
    final DCRContext context = DCRContextImplementation.create(null);

    final List<Instrumenter> instrumenters =
        new JythonScriptEngineService(properties, context, m_pyScript).createInstrumenters();

    assertEquals(1, instrumenters.size());

    final Instrumenter instrumenter = instrumenters.get(0);

    assertEquals("traditional Jython instrumenter", instrumenter.getDescription());

    final Object foo = new Object();

    PySystemState.initialize();

    final PyObject proxy = (PyObject) instrumenter.createInstrumentedProxy(m_test, m_recorder, foo);

    assertSame(proxy.__getattr__("__target__").__tojava__(Object.class), foo);

    try {
      instrumenter.createInstrumentedProxy(m_test, m_recorder, new PyObject());
      fail("Expected NotWrappableTypeException");
    } catch (NotWrappableTypeException e) {
    }
  }
Exemplo n.º 3
0
 public void cleanup() {
   systemState.callExitFunc();
   try {
     Py.getSystemState().stdout.invoke("flush");
   } catch (PyException pye) {
     // fall through
   }
   try {
     Py.getSystemState().stderr.invoke("flush");
   } catch (PyException pye) {
     // fall through
   }
 }
Exemplo n.º 4
0
  /**
   * Shut down the engine.
   *
   * <p>We don't use m_interpreter.cleanup(), which delegates to PySystemState.callExitFunc, as
   * callExitFunc logs problems to stderr. Instead we duplicate the callExitFunc behaviour raise our
   * own exceptions.
   *
   * @throws EngineException If the engine could not be shut down.
   */
  @Override
  public void shutdown() throws EngineException {

    final PyObject exitfunc = m_systemState.__findattr__("exitfunc");

    if (exitfunc != null) {
      try {
        exitfunc.__call__();
      } catch (final PyException e) {
        throw new JythonScriptExecutionException("calling script exit function", e);
      }
    }
  }
 {
   PySystemState.initialize();
 }
Exemplo n.º 6
0
 /**
  * Set the Python object to use for the standard output stream
  *
  * @param outStream Python file-like object to use as output stream
  */
 public void setOut(PyObject outStream) {
   systemState.stdout = outStream;
 }
Exemplo n.º 7
0
 /**
  * Initializes the jython runtime. This should only be called once, and should be called before
  * any other python objects are created (including a PythonInterpreter).
  *
  * @param preProperties A set of properties. Typically System.getProperties() is used.
  * @param postProperties An other set of properties. Values like python.home, python.path and all
  *     other values from the registry files can be added to this property set. PostProperties will
  *     override system properties and registry properties.
  * @param argv Command line argument. These values will assigned to sys.argv.
  */
 public static void initialize(
     Properties preProperties, Properties postProperties, String[] argv) {
   PySystemState.initialize(preProperties, postProperties, argv);
 }
Exemplo n.º 8
0
 public void setErr(PyObject outStream) {
   systemState.stderr = outStream;
 }
 public void cleanup() {
   systemState.callExitFunc();
 }