Python script output

I’ve posted a similar question a while back but could not provide a travis build link for the issue, now I can: https://travis-ci.com/gplayersv/travis-testing/builds/116104943
My issue is that the output of the python script is not displayed as the script prints stuff out but only when it finishes running. Script doesn’t take long to run so maybe there’s some buffering here.
I noticed this happens only if I have a travis secret env var (don’t display it’s value set to True).
I would like to understand what happens. Is travis parsing the output and looking for all secret env vars in order to replace them?

That’s exactly what happens. See after_failure output gets truncated unless sleep is used · Issue #6018 · travis-ci/travis-ci.

Output loss is still a problem AFAICT if a command produces lots of output very quickly before failing. So I use trap 'sleep 3' ERR whenever I hit it. 3 seconds seems enough for the logging machinery to “catch up” before terminating the build.

1 Like

Is there any way to tell Travis to just blurt out output as received for a given command?
Something like no_escape python scripts/do_stuff.py

Also, how come I often get to 10 minutes of no output coming from a python script which prints something as soon as it’s called and then keeps printing from time to time? This leads to travis terminating the build and I have no output as to what went wrong. I’m trying to understand what could be happening but I can’t.
I understand why it buffers the output but don’t undestand why it can take so long to print something, I would expect it to print somthing at least at 30-60 secs.

Run the build without secret variables or (better) change your script to output line breaks regularly – at least when the output is not to a terminal.

With secret variables, the output is by necessity line-buffered so you won’t get any output until your program produces a line break.

We need the secret variables so removing them is not an option.
I believe that the output is connected to the terminal since I just do print statements in the python script, no changing sys.stdout, no logging or anything, but I will confirm this by adding something like print('Stdout is{}connected to a terminal.'.format(sys.stdout.isatty() and ' ' or ' not ')) to the script.
Since I’m doing things like print("something"), ... do more work, ...print("something else") I assume these are line breaks and should be buffered, am I right?

Imprint