title: PyInstaller unbuffered stdio
body: <h1>Problem</h1>
  
  <p>Docker image sizes should commonly be as small as possible. Using full-blown environments like a <a href="https://hub.docker.com/_/python/" rel="noreferrer">standard python</a> image results often, with all dependencies installed, in heavily bloated images. Packaging python into stand-alone executables (e.g. using pyinstaller) is a perfect way of reducing image sizes and overall complexity.</p>
  
  <p><strong>Environment</strong>: <code>python3.6</code>, <code>pyinstaller==3.4</code></p>
  
  <p>The problem arising is, that python uses per default buffered stdio. This can be mitigated by running python scripts with <code>python -u ...</code>. But becomes inaccessible when using pyinstaller.</p>
  
  <p>According to the <a href="https://pyinstaller.readthedocs.io/en/v3.4/spec-files.html#giving-run-time-python-options" rel="noreferrer">docs</a> it should be possible to add run-time options, such as <code>u</code>, <code>v</code> and <code>W ...</code> to the executable generated. But unfortunately in reality it doesn't seem to work. Both, <code>v</code> and <code>W</code>, work normally, but <code>u</code> seems to be completely ignored.</p>
  
  <p>The following snippet shows the usage:</p>
  
  <pre><code>...
  exe = EXE(...
            [('u', None, 'OPTION')],
            name="myapp",
            ...)
  ...
  </code></pre>
  
  <p>Is this flag still valid? Since the others work - has it been removed without notice or update of the docs?</p>
  
  <p>Are there alternatives to disable buffering of stdio (with pyinstaller or as well externally), <em>without</em> modifying the python code, like <a href="https://stackoverflow.com/questions/107705/disable-output-buffering">so</a>?</p>
  
  <h1>Why would that be needed?</h1>
  
  <p>Buffered IO is to be avoided, when running docker swarm services. In order to make the executable properly log in real-time to the docker daemon, it's necessary to attach a shell. But the attaching of a tty shell to the swarm tasks makes working with the logs much, much more complicated if even impossible.</p>