I have a python script that is called from a java program 
The java program feeds data to the python script sys.stdin and the java program receives data from the python process outputstream . 
What is know is this .
running the command  'python script.py' from the java program on 10MB of data takes about 35 seconds.
However running the commands  'python script.py > temp.data ' and then  cat temp.data  is  significantly faster. 
The order of magnitude of performance is even more drastic as the data gets larger.
In order to address this , I am thinking maybe there is a way to change the sys.stdout to mimic what I am doing.
Or maybe I can pipe the python script output to a virtual file .
Any recommendations ?
This is probably a buffering problem when you have the Java program writing to one filehandle and reading from another filehandle. The order of those in the Java and the size of the writes is suboptimal and it's slowing itself down.
I would try "python -u script.py" to see what it does when you ask python to unbuffer, which should be slower but might trick your calling program into racing a different way, perhaps faster.
The larger fix, I think, is to batch your code, as you are testing with, and read the resulting file, or to use posix select() or filehandle events to handle how your java times its writes and reads.
receiving data from java program that calls python script is too slow