I am running python process from Java (openjdk 1.7.0_85)
:
ProcessBuilder pb = new ProcessBuilder(bin, processJar, Integer.toString(port), Integer.toString(portRev), path, extl, thriftc, thrifts, thriftd);
pb.inheritIO();
pb.redirectErrorStream(true);
pb.directory(new File(dir));
try {
logger.trace("Start process");
lock.lock();
process = pb.start();
cond.await();
lock.unlock();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
I set pb.inheritIO()
to redirect python prints to standard output. If my python process do some simple things redirection of streams works as expected.
I am using thriftpy (0.3.2)
for Java-Python
communication. Python process opens a thrift server in a thread:
def __run_server(self, serverport):
t = Globals.thrifts.split(',')
thrifts = thriftpy.load(t[0], module_name="processsideserver_thrift", include_dirs=[t[1]])
self.server = make_server(thrifts.ProcessSideServer, self, '127.0.0.1', serverport)
def run(self):
if self.can_run == True:
self.running = True
try:
self.server.serve()
except Exception:
''
as self.server.serve()
is a blocking function. Because of this line my redirection of streams stopped working. Application and Java-Python communication works fine. But python prints are not showing up in Console.
Thrifpy code is like:
def serve(self):
self.trans.listen()
while not self.closed:
try:
client = self.trans.accept()
t = threading.Thread(target=self.handle, args=(client,))
t.setDaemon(self.daemon)
t.start()
except KeyboardInterrupt:
raise
except Exception as x:
logging.exception(x)
Why it is like that? Because of deamon thread? How can I force redirection of streams anyway?