Python:如何检测调试解释器 [英] Python: How to detect debug interpreter
问题描述
如果我的python脚本是由调试解释器(即python_d.exe而不是python.exe)运行的,我该如何检测?我需要改变路径到一些我传递给扩展名的DLL。
How can I detect in my python script if its being run by the debug interpreter (ie python_d.exe rather than python.exe)? I need to change the paths to some dlls that I pass to an extension.
例如,我喜欢在我的python脚本开始时做这样的事情:
eg Id like to do something like this at the start of my python script:
#get paths to graphics dlls
if debug_build:
d3d9Path = "bin\\debug\\direct3d9.dll"
d3d10Path = "bin\\debug\\direct3d10.dll"
openGLPath = "bin\\debug\\openGL2.dll"
else:
d3d9Path = "bin\\direct3d9.dll"
d3d10Path = "bin\\direct3d10.dll"
openGLPath = "bin\\openGL2.dll"
我想到在扩展中添加一个IsDebug()方法,如果它是是调试版本(即使用#define DEBUG构建),否则为false。但是,这似乎是一件事情,我确信我可以让python告诉我...
I thought about adding an "IsDebug()" method to the extension which would return true if it is the debug build (ie was built with "#define DEBUG") and false otherwise. But this seems a bit of a hack for somthing Im sure I can get python to tell me...
推荐答案
Distutils使用 sys.gettotalrefcount
来检测调试python构建:
Distutils use sys.gettotalrefcount
to detect a debug python build:
# ...
if hasattr(sys, 'gettotalrefcount'):
plat_specifier += '-pydebug'
- 此方法不依赖在可执行文件名称'
* _ d.exe
'。它适用于任何名称。 - 此方法是跨平台的。它不依赖于'
_d.pyd
'后缀。 - this method doesn't rely on an executable name '
*_d.exe
'. It works for any name. - this method is cross-platform. It doesn't depend on '
_d.pyd
' suffix.
调试版本和 Misc / SpecialBuilds.txt
这篇关于Python:如何检测调试解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!