Re: [PATCH] oeqa/qemurunner: do not use Popen.poll() when terminating runqemu with a signal

Mikko Rapeli


On Mon, Jan 30, 2023 at 11:11:25PM +0100, Alexander Kanavin wrote:
This does not actually guarantee that the child runqemu process has completely exited:
poll() may return prematurely while the SIGTERM handler in runqemu is still running.
This thwarts the rest of the processing, and may terminate the handler before
it completes.

Use Popen.communicate() instead: this is what python documentation recommends as well:
Was I trying to solve the same problem in ?

I think so.



Signed-off-by: Alexander Kanavin <alex@...>
meta/lib/oeqa/utils/ | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/meta/lib/oeqa/utils/ b/meta/lib/oeqa/utils/
index b5fed6c9fe..8b893601d4 100644
--- a/meta/lib/oeqa/utils/
+++ b/meta/lib/oeqa/utils/
@@ -543,10 +543,13 @@ class QemuRunner:
except OSError as e:
if e.errno != errno.ESRCH:
- endtime = time.time() + self.runqemutime
- while self.runqemu.poll() is None and time.time() < endtime:
- time.sleep(1)
- if self.runqemu.poll() is None:
+ try:
+ outs, errs = self.runqemu.communicate(timeout = self.runqemutime)
+ if outs:
+"Output from runqemu:\n%s", outs.decode("utf-8"))
+ if errs:
+"Stderr from runqemu:\n%s", errs.decode("utf-8"))
+ except TimeoutExpired:
self.logger.debug("Sending SIGKILL to runqemu")
os.killpg(os.getpgid(, signal.SIGKILL)
if not self.runqemu.stdout.closed:

Join to automatically receive all group messages.