[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion/shell JythonShell.java,1.2,1
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-08-25 00:04:13
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/shell In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17081/src/org/python/pydev/editor/codecompletion/shell Modified Files: JythonShell.java PythonShell.java AbstractShell.java Log Message: Index: JythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/shell/JythonShell.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JythonShell.java 19 Aug 2005 16:48:32 -0000 1.2 --- JythonShell.java 25 Aug 2005 00:04:03 -0000 1.3 *************** *** 28,43 **** process = new SimplePythonRunner().createProcess(executableStr, serverFile.getParentFile()); - try { - process.getOutputStream().close(); //we won't write to it... - } catch (IOException e2) { - } - - //will print things if we are debugging or just get it (and do nothing except emptying it) - ThreadStreamReaderPrinter std = new ThreadStreamReaderPrinter(process.getInputStream()); - ThreadStreamReaderPrinter err = new ThreadStreamReaderPrinter(process.getErrorStream()); - - std.start(); - err.start(); - return executableStr; } --- 28,31 ---- Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/shell/PythonShell.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PythonShell.java 19 Aug 2005 16:48:32 -0000 1.3 --- PythonShell.java 25 Aug 2005 00:04:03 -0000 1.4 *************** *** 52,67 **** } process = new SimplePythonRunner().createProcess(execMsg, serverFile.getParentFile()); - - try { - process.getOutputStream().close(); //we won't write to it... - } catch (IOException e2) { - } - - //will print things if we are debugging or just get it (and do nothing except emptying it) - ThreadStreamReaderPrinter std = new ThreadStreamReaderPrinter(process.getInputStream()); - ThreadStreamReaderPrinter err = new ThreadStreamReaderPrinter(process.getErrorStream()); - - std.start(); - err.start(); return execMsg; --- 52,55 ---- Index: AbstractShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/shell/AbstractShell.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** AbstractShell.java 19 Aug 2005 18:44:10 -0000 1.7 --- AbstractShell.java 25 Aug 2005 00:04:03 -0000 1.8 *************** *** 27,30 **** --- 27,31 ---- import org.python.pydev.plugin.PydevPlugin; import org.python.pydev.plugin.SocketUtil; + import org.python.pydev.runners.ThreadStreamReader; public abstract class AbstractShell { *************** *** 34,38 **** public static final int COMPLETION_SHELL = 1; protected static final int DEFAULT_SLEEP_BETWEEN_ATTEMPTS = 1000; ! protected static final boolean DEBUG_SHELL = false; --- 35,39 ---- public static final int COMPLETION_SHELL = 1; protected static final int DEFAULT_SLEEP_BETWEEN_ATTEMPTS = 1000; ! protected static final boolean DEBUG_SHELL = true; *************** *** 190,193 **** --- 191,196 ---- */ protected ServerSocket serverSocket; + private ThreadStreamReader stdReader; + private ThreadStreamReader errReader; *************** *** 251,255 **** String execMsg = createServerProcess(pWrite, pRead); ! //dbg("executing "+execMsg); sleepALittle(200); --- 254,258 ---- String execMsg = createServerProcess(pWrite, pRead); ! dbg("executing "+execMsg); sleepALittle(200); *************** *** 266,269 **** --- 269,275 ---- } + //ok, process validated, so, let's get its output and store it for further use. + afterCreateProcess(); + boolean connected = false; int attempts = 0; *************** *** 296,302 **** //what, after all this trouble we are still not connected????!?!?!?! //let's communicate this to the user... ! Exception exception = new Exception("Error connecting to python process (" + execMsg + ")"); try { ! Status status = PydevPlugin.makeStatus(IStatus.ERROR, "Error connecting to python process (" + execMsg + ")", exception); throw new CoreException(status); } catch (Exception e) { --- 302,318 ---- //what, after all this trouble we are still not connected????!?!?!?! //let's communicate this to the user... ! String isAlive; try { ! int exitVal = process.exitValue(); //should throw exception saying that it still is not terminated... ! isAlive = " - the process in NOT ALIVE anymore (output="+exitVal+") - "; ! } catch (IllegalThreadStateException e2) { //this is ok ! isAlive = " - the process in still alive - "; ! } ! ! ! String output = getProcessOutput(); ! Exception exception = new Exception("Error connecting to python process (" + execMsg + ") "+isAlive+" the output of the process is: "+output); ! try { ! Status status = PydevPlugin.makeStatus(IStatus.ERROR, "Error connecting to python process (" + execMsg + ") "+isAlive+" the output of the process is: "+output, exception); throw new CoreException(status); } catch (Exception e) { *************** *** 317,320 **** --- 333,366 ---- + private void afterCreateProcess() { + try { + process.getOutputStream().close(); //we won't write to it... + } catch (IOException e2) { + } + + //will print things if we are debugging or just get it (and do nothing except emptying it) + stdReader = new ThreadStreamReader(process.getInputStream()); + errReader = new ThreadStreamReader(process.getErrorStream()); + + stdReader.start(); + errReader.start(); + } + + + /** + * @return the current output of the process + */ + protected String getProcessOutput(){ + try { + String output = ""; + output += "Std output:\n" + stdReader.contents.toString(); + output += "\n\nErr output:\n" + errReader.contents.toString(); + return output; + } catch (Exception e) { + return "Unable to get output"; + } + } + + /** * @param pWrite the port where we should write |