Python:如何检测debug interp

2024-10-01 17:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在python脚本中检测它是否由调试解释器(即python_d.exe而不是python.exe)? 我需要更改传递给扩展名的一些dll的路径。在

例如,我想在python脚本的开头做这样的事情:

#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()”方法,如果是调试版本,它将返回true(即使用“#define debug”构建),否则返回false。但这似乎有点像黑客,我相信我可以让python告诉我。。。在


Tags: debug路径脚本getbin事情exe解释器
3条回答

一种简单的方法,如果您不介意依赖文件名:

if sys.executable.endswith("_d.exe"):
  print "running on debug interpreter"

您可以阅读有关sys模块及其各种工具here的更多信息。在

Distutils use ^{} to detect a debug python build

# ...
if hasattr(sys, 'gettotalrefcount'):
   plat_specifier += '-pydebug'
  • 此方法不依赖可执行文件名“*_d.exe”。它对任何名字都有效。在
  • 这种方法是跨平台的。它不依赖于'_d.pyd'后缀。在

Debugging BuildsMisc/SpecialBuilds.txt

更好的方法是检查

imp.get_suffixes()

对于调试版本,它包含以''u d.pyd'开头的元组:

^{pr2}$

相关问题 更多 >

    热门问题