[ptest-runner2] [PATCH] main.c: Set PYTHONUNBUFFERED in the environment
Richard Purdie <[email protected]> Wed, 4 Mar 2026 16:04:16 +0000
| Newsgroups | org.yoctoproject.lists.yocto |
|---|---|
| Message-ID | <[email protected]> |
When python tests are run, on a normal terminal they output unbuffered but they behave differently, buffering the output. This creates issues with the timeout handling that ptest-runner uses. This is the cause of some of the strange ptest timeout issues we see. Set the environment variable in all cases to avoid this. An alternative would be to update every ptest runner script that uses python but that seems to be a lot of work for no good reason when we can just set it here. Signed-off-by: Richard Purdie <[email protected]> --- main.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.c b/main.c index 594d198..3d5b0d4 100644 --- a/main.c +++ b/main.c @@ -238,6 +238,13 @@ main(int argc, char *argv[]) for (i = 0; i < ptest_exclude_num; i++) ptest_list_remove(run, opts.exclude[i], 1); + /* python programs need to use unbuffered output for our timeouts to work correctly */ + rc = putenv("PYTHONUNBUFFERED=1"); + if (rc) { + fprintf(stderr, "Couldn't putenv: %d\n", rc); + exit(1); + } + rc = run_ptests(run, opts, argv[0], stdout, stderr); fprintf(stdout, "TOTAL: %d FAIL: %d\n", ptest_list_length(run), rc); if (rc > 0)