PyInstaller unbuffered stdio

谁说胖子不能爱 提交于 2020-08-22 05:16:00

问题


Problem

Docker image sizes should commonly be as small as possible. Using full-blown environments like a standard python 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.

Environment: python3.6, pyinstaller==3.4

The problem arising is, that python uses per default buffered stdio. This can be mitigated by running python scripts with python -u .... But becomes inaccessible when using pyinstaller.

According to the docs it should be possible to add run-time options, such as u, v and W ... to the executable generated. But unfortunately in reality it doesn't seem to work. Both, v and W, work normally, but u seems to be completely ignored.

The following snippet shows the usage:

...
exe = EXE(...
          [('u', None, 'OPTION')],
          name="myapp",
          ...)
...

Is this flag still valid? Since the others work - has it been removed without notice or update of the docs?

Are there alternatives to disable buffering of stdio (with pyinstaller or as well externally), without modifying the python code, like so?

Why would that be needed?

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.

来源:https://stackoverflow.com/questions/52302361/pyinstaller-unbuffered-stdio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!