PyInstaller无缓冲stdio [英] PyInstaller unbuffered stdio

查看:74
本文介绍了PyInstaller无缓冲stdio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Docker映像大小通常应尽可能小.经常使用成熟的环境(例如标准python 图像),并且安装了所有依赖项images肿的图像.将python打包到独立的可执行文件中(例如使用pyinstaller)是减少映像大小和整体复杂性的理想方法.

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.

环境: python3.6 pyinstaller == 3.4

出现的问题是,python默认使用默认的缓冲stdio.这可以通过使用 python -u ... 运行python脚本来缓解.但是使用pyinstaller时无法访问.

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.

根据文档应该可以向生成的可执行文件中添加运行时选项,例如 u v W ... .但不幸的是,实际上它似乎不起作用. v W 都可以正常工作,但是 u 似乎被完全忽略了.

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?

是否有其他方法可以禁用stdio缓冲(使用pyinstaller或在外部),无需修改python代码,例如

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

在运行docker swarm服务时,应避免使用缓冲的IO.为了使可执行文件正确地实时登录到Docker守护程序,必须附加一个Shell.但是,将tty shell附加到swarm任务上会使处理日志变得非常复杂,甚至是不可能的.

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.

推荐答案

至少在Windows上已损坏(请参见文档中.

At least it is broken on Windows (See issue on github) and it’s not in the docs.

这篇关于PyInstaller无缓冲stdio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆