| Message ID | 20260304160454.1988923-1-richard.purdie@linuxfoundation.org |
|---|---|
| State | New |
| Headers | show |
| Series | [ptest-runner] main.c: Set PYTHONUNBUFFERED in the environment | expand |
Applied thanks!, If we add more variables or cases to the environment, we could refactor to a function later. On Wed, Mar 4, 2026 at 10:04 AM Richard Purdie < richard.purdie@linuxfoundation.org> wrote: > 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 <richard.purdie@linuxfoundation.org> > --- > 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) >
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)
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 <richard.purdie@linuxfoundation.org> --- main.c | 7 +++++++ 1 file changed, 7 insertions(+)