强制使用 buildout 和 zc.recipe.egg:scripts 制作的脚本进行无缓冲输出
我需要在使用构建构建的脚本中使用无缓冲的输出。
我的方法是在生成的脚本中为 Python 指定 -u
标志。
这是我的 buildout.cfg:
[buildout]
parts = python
develop = .
[python]
recipe = zc.recipe.egg:scripts
eggs = myproject
和 setup.py:
from setuptools import setup, find_packages
setup(
name = 'myproject',
packages = find_packages(),
entry_points = """
[console_scripts]
myscript = myproject:main
""",
)
使用此配置我得到以下 shebang:
$ pip install .
$ head -n1 /usr/local/bin/myscript
#!/usr/bin/python
我想要这个:
#!/usr/bin/python -u
如何做到这一点?我尝试将 arguments = -u
和 interpreter = python -u
添加到 buildout.cfg
中。它不起作用。
I need to use unbuffered output in a script that is built with buildout.
My approach was to specify the -u
flag for Python in the generated script.
Here's my buildout.cfg:
[buildout]
parts = python
develop = .
[python]
recipe = zc.recipe.egg:scripts
eggs = myproject
And setup.py:
from setuptools import setup, find_packages
setup(
name = 'myproject',
packages = find_packages(),
entry_points = """
[console_scripts]
myscript = myproject:main
""",
)
I get the following shebang with this configuration:
$ pip install .
$ head -n1 /usr/local/bin/myscript
#!/usr/bin/python
And I want this:
#!/usr/bin/python -u
How to do it? I tried adding arguments = -u
and interpreter = python -u
to buildout.cfg
. It didn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在文件号上打开一个新文件对象来重新打开 stdin 或 stdout,从而在 Python 脚本中强制使用无缓冲 I/O:
如果您想使用使用 stdout 的其他模块或内置程序,则可以重新分配 sys.stdout或标准输入:
另请参阅 无缓冲标准输出来自程序内的 python(如 python -u)
You can force unbuffered I/O from within your Python script by re-opening stdin or stdout by opening a new file object on the filenumber:
You can then reassign sys.stdout if you want to use other modules or build-ins that use stdout or stdin:
Also see unbuffered stdout in python (as in python -u) from within the program