From a5a1ecb806ec2dec26701b931b8d2d6cbe7f4928 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 21 Jun 2019 20:59:15 +0300 Subject: [PATCH] Read output from external task while waiting Waiting for the process to finish first may lead to a deadlock if it produces more output than can fit in the pipe's buffers. --- source/externaltask.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/externaltask.cpp b/source/externaltask.cpp index d9832c2..f7ab199 100644 --- a/source/externaltask.cpp +++ b/source/externaltask.cpp @@ -128,9 +128,9 @@ Task::Status ExternalTask::wait() Task::Status ExternalTask::do_wait(bool block) { - if(process) + while(process) { - if(process->wait(block)) + if(process->wait(!capture_pipe)) { exit_code = process->get_exit_code(); delete process; @@ -138,7 +138,7 @@ Task::Status ExternalTask::do_wait(bool block) } // Do this after waiting to avoid a race condition - while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, Time::zero)) + while(capture_pipe && IO::poll(*capture_pipe, IO::P_INPUT, 10*Time::msec)) { char buf[1024]; unsigned len = capture_pipe->read(buf, sizeof(buf)); @@ -149,7 +149,10 @@ Task::Status ExternalTask::do_wait(bool block) } if(process) - return RUNNING; + { + if(!block) + return RUNNING; + } else signal_finished.emit(!exit_code); } -- 2.45.2