[Pydev-code] Process spawn doubt
Brought to you by:
fabioz
From: Fabio Z. <fa...@in...> - 2004-08-16 19:44:48
|
Hi all, I'm trying to figure out how to do the code completion usable (in my machine it is very annoying having to wait for the completion, so, I'm trying to remove the places that I think really let it slow: creating a file for the process to get and spawning a Python process each time). In order to do it, I should spawn a process and then communicate with it to get the info I want. It should be easy, but I'm having the following problem: when I spawn the process, I can write to its outputstream without any problem, but it only responds once I close the outputstream. The code below explains it better (I think....) Check the comments in main().... I'm also putting a file attached with the code, if someone wants to know all I'm doing... Aleks, I tried to use what you've done in the debug, but it seemed to me that it adds a lot of overhead to what I want to do, so, it would (I think) become unusable, but maybe you can explain the concepts you used so that I can try to do it in a lightweight manner.... /** * @throws IOException */ public void startIt() throws IOException { if (p != null){ p.destroy(); } p = Runtime.getRuntime().exec("python"); //get the process //get outputs / inputs in = new BufferedReader(new InputStreamReader(p.getInputStream())); eIn = new BufferedReader(new InputStreamReader(p.getErrorStream())); stream = new BufferedOutputStream(p.getOutputStream()); } public static void main(String[] args) throws IOException, InterruptedException { final PythonShell s = new PythonShell(); new Thread(){ public void run(){ try { //print the output in this Thread s.printStdOutput(); s.printErrorOutput(); } catch (Exception e) { e.printStackTrace(); } } }.start(); for(int i=0;i<2;i++){ String str = "print 'aaaaaa'\n"; s.stream.write(str.getBytes()); s.stream.flush(); } /* s.stream.close(); */ // if I uncomment this line it executes the code in python, // otherwise it doesn't. // The bad thing is: if I do close it, I can't // write to it anymore and the code below will crash. // and I have to go and create a new process. for(int i=0;i<2;i++){ String str = "print 'aaaaaa'\n"; s.stream.write(str.getBytes()); s.stream.flush(); } } []s Fabio Zadrozny ------------------------------------------------------ Software Developer ESSS - Engineering Simulation and Scientific Software www.esss.com.br -----Original Message----- From: pyd...@li... [mailto:pyd...@li...] On Behalf Of Aleks Totic Sent: sexta-feira, 13 de agosto de 2004 17:47 To: pyd...@li... Subject: Re: [Pydev-code] OsCon Presentation on PyDev Nice presentation at OsCon. I've created a press section on the web site with these references. Aleks Dana Moore wrote: > Fabio and Aleks, > Just wanted to mention that there is a preso at: > > http://conferences.oreillynet.com/presentations/os2004/moore_python.pd > f > > that gives some of the highlights of the current release > > Also, you were probabaly aware of the article at: > http://www-106.ibm.com/developerworks/library/os-ecant/?ca=drs-tp2604 > that presents details of the current release at a nice level as well ------------------------------------------------------- SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 _______________________________________________ Pydev-code mailing list Pyd...@li... https://lists.sourceforge.net/lists/listinfo/pydev-code |