# Python script output

**URL:** <https://travis-ci.community/t/python-script-output/3811>\
**Category:** Python\
**Created:** [June 19, 2019, 11:22am UTC](https://travis-ci.community/t/python-script-output/3811 "2019-06-19T11:22:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gplayersv](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/gplayersv/32/1976_2.png) [@gplayersv](https://travis-ci.community/u/gplayersv)\
**Post date:** [June 19, 2019, 11:22am UTC](https://travis-ci.community/t/python-script-output/3811/1 "2019-06-19T11:22:35Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [June 21, 2019, 8:45pm UTC](https://travis-ci.community/t/python-script-output/3811/2 "2019-06-21T20:45:47Z")

</div>

> [@gplayersv](#):
>
> 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](https://github.com/travis-ci/travis-ci/issues/6018#issuecomment-370023238).

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.

---

<div class="post-metadata">

**Author:** ![gplayersv](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/gplayersv/32/1976_2.png) [@gplayersv](https://travis-ci.community/u/gplayersv)\
**Post date:** [July 2, 2019, 10:40am UTC](https://travis-ci.community/t/python-script-output/3811/3 "2019-07-02T10:40:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![native-api](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/native-api/32/430_2.png) [@native-api](https://travis-ci.community/u/native-api)\
**Post date:** [July 2, 2019, 10:56am UTC](https://travis-ci.community/t/python-script-output/3811/4 "2019-07-02T10:56:05Z")

</div>

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](https://docs.python.org/3/library/os.html?highlight=isatty#os.isatty).

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

---

<div class="post-metadata">

**Author:** ![gplayersv](https://sea1.discourse-cdn.com/flex015/user_avatar/travis-ci.community/gplayersv/32/1976_2.png) [@gplayersv](https://travis-ci.community/u/gplayersv)\
**Post date:** [July 2, 2019, 11:38am UTC](https://travis-ci.community/t/python-script-output/3811/5 "2019-07-02T11:38:35Z")

</div>

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?
