有没有一个标志,我可以检查我的代码,看看PyCharm的调试器是否正在运行? [英] Is there a flag I can check in my code to see if PyCharm's debugger is running?

查看:1568
本文介绍了有没有一个标志,我可以检查我的代码,看看PyCharm的调试器是否正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的代码中采取一些行动,条件是PyCharm调试器是否已经连接并运行 - 例如,我已经使用IDE的Debug命令启动了我的代码;如果这样的话,像$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

有没有办法?

解决方案

由于Pycharm调试器已经与Pydev的,您可能希望此答案



编辑



为了确定脚本是否由Pycharm启动,我可以想到在运行/调试配置





然后检查:

 如果os.environ中的PYCHARM:
print(在Pycharm中运行)

其实最方便的方式可能会直接编辑默认运行配置,以便在任何新的运行中自动将该标志整合。




I'd like to take some actions in my code, conditioned on whether the PyCharm debugger is attached and running — e.g., I've launched my code using the IDE's "Debug" command; something like

if pycharm_debugger_is_running:
    do_something()
else:
    do_another_thing()

Is there a way to do that?

解决方案

Since Pycharm debugger has been merged with Pydev's, you may like this answer.

Edit

In order to determine whether the script was launched by Pycharm, I can think of manually adding your own environment variable in the Run/Debug Configurations

And then check for it:

if 'PYCHARM' in os.environ:
    print("running in Pycharm")

Actually the most convenient way would probably be to directly edit the default run configuration to automatically integrate that flag in any new run.

这篇关于有没有一个标志,我可以检查我的代码,看看PyCharm的调试器是否正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆