windows Python ctypes:如何从 stderr 刷新输出?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6298940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:02:29  来源:igfitidea点击:

Python ctypes: How do I flush output from stderr?

pythonwindowsdllctypes

提问by Ryan

I've written some function callbacks using python's ctypes to access functions in a DLL. The code used to build that DLL has some debugging print statements in it using fprintf to stderr. However, when I run my python code, I don't see that output to stderr consistently. Only rarely I will see it flush the output from stderr to the console that I'm using. I've tried running it with "python -u foo.py", but that doesn't help either. Any suggestions?

我已经使用 python 的 ctypes 编写了一些函数回调来访问 DLL 中的函数。用于构建该 DLL 的代码中有一些使用 fprintf 到 stderr 的调试打印语句。但是,当我运行我的 python 代码时,我没有看到一致的输出到 stderr。我很少会看到它将 stderr 的输出刷新到我正在使用的控制台。我试过用“python -u foo.py”运行它,但这也无济于事。有什么建议?

回答by Ignacio Vazquez-Abrams

It's all the same stderr.

都是一样的标准错误。

sys.stderr.flush()