如何知道 python 编程是否在分析器下 运行?

How to know if a python programming is running under a profiler?

有什么方法可以判断一个Python脚本当前是否运行在profiler下?

我有一个带有 GUI 的程序。我想在 profiler 下 运行 时跳过 GUI 部分,以便结果更准确。

Explicit is better than implicit. 只需在您的程序中添加一个禁用 GUI 的命令行选项。如果您使用 argparse:

args.add_argument('--no-gui', action='store_true')