I have some python code that calls a bash script that calls another python file. I'm trying to debug the code in PyCharm but breakpoints in the innermost file don't seem to be getting reached.
The code is set-up is as follows:
outter.py calls-> bash_script calls-> inner.py
I put breakpoints in inner.py but when I try debugging outter.py the breakpoints in inner.py aren't reached. I put some print statements in inner.py that print to stdout so I know the file is actually getting reached.
Admittedly, it's been a hot second since I've used PyCharm so I don't quite know if I'm doing something wrong or if something weird is going on because of the bash file.
EDIT: The specific calls are as follows:
#outter.py
...
subprocess.run('./bash_script param1', shell=True)
...
#bash_script
...
python3 -m inner.py "$@"
...
PyCharm has in fact a special support for such cases, it's called "Python Remote Debug" (which is not the obvious naming, but I created a ticket to fix that https://youtrack.jetbrains.com/issue/PY-39230).
Here is the relevant doc page: https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config You can ignore "remote" part altogether.
You basically need "Python Remote Debug" run configuration, which start the debugger Java frontend in a loop waiting for a connection from a Python backend (pydevd-pycharm).
Install pydevd-pycharm on the interpreter used to run inner.py and add
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=12345, stdoutToServer=True, stderrToServer=True)
somewhere inside inner.py where you want to stop (adjust the port if needed). Than run outter.py. It will call bash, bash will call inner.py, inner.py will call pydevd_pycharm, pydevd_pycharm will establish connection to the debugger Java frontend and pause the script execution. Now switch to debugger toolwindow in PyCharm and step through your code as usual.
I created a ticket to improve docs as well https://youtrack.jetbrains.com/issue/PY-39229 Feel free to vote/comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With