Gre*_*urm 3 python debugging terminal pycharm
我想调试一个Python需要多个命令行参数的脚本,例如
myscript.py --input1 ./dir/file1.txt --input2 ./dir/file2.txt
Run Code Online (Sandbox Code Playgroud)
在中Pycharm。我知道,我可以使用Run/Debug Configuration添加命令行参数。但是,我觉得这很麻烦,因为每次我要修改参数时都必须打开菜单。此外,将文件指定为参数时没有文件名完成。
我更喜欢myscript.py从我最喜欢的外壳进行调用,该外壳具有文件名补全等功能,但是仍然PyCharm在该脚本上使用调试器。
简短答案: Tools> Attach to Process...
长分析器:
在您的代码的第一行放置以下行
input("press Enter to continue")
Run Code Online (Sandbox Code Playgroud)在shell中启动代码
myscript.py --input1 ./dir/file1.txt --input2 ./dir/file2.txt
Run Code Online (Sandbox Code Playgroud)打开Pycharm并用它打开您的myscript.py。设置break points在您想调试的任何地方。选择Tools> Attach to Process...并选择myscript.py正在运行的进程。
回到外壳myscript.py并击中Enter
您可能会遇到的麻烦:ptrace没有做某事的许可
解:
sudo su
echo 0 > /proc/sys/kernel/yama/ptrace_scope
Run Code Online (Sandbox Code Playgroud)
或者您可以直接在其中设置0
/etc/sysctl.d/10-ptrace.conf
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
859 次 |
| 最近记录: |