hlg wrote: ↑Fri Jul 12, 2019 10:30 am
However you don't need remote debugging as long as PyCharm and the FreeCAD application are running on the same machine. You can just attach the remote debugger to a running FreeCAD instance and off you go. In PyCharm this can be found under Run / Attach To Process or with Ctrl-Alt-F5. You are presented with a list of processes to select from. You can configure the processes to appear in this list under File / Settings / Build, Execution, Deployment / Python Debugger. There you can specify a string. All the processes containing this string in their name will appear in the process list to select from later on. The initial search string is "python" such that FreeCAD will not appear in the list. Changing it to "FreeCAD" should work. When in doubt, inspect the list of running processes with the tools of your OS and also note the process ID.
Hi @hlg,
I followed your instructions with the community edition of PyCharm but I couldn't attach the debugger. First, I found the process ID of the running FreeCAD instance, and then tried to connect. The error I received is below. I think the problem is that FreeCAD does not recognize the `--port` flag. How did you solve it? Another question: when you change the values of variables or create new objects in debug mode, are the changes reflected in the running FreeCAD instance the debugger is attached to? Thank you in advance.
steelman wrote: ↑Tue Apr 20, 2021 11:04 am
I open FreeCAD. I enter the following into the console to load my version of Arch workbench (especially ArchWindow module)
import importlib # to use reload() later
sys.path.insert(0, "/home/steelman/src/FreeCAD/src/Mod/Arch")
for m in [k for k in sys.modules.keys() if 'Arch' in k]: sys.modules.pop(m, None)
import Arch
When I try to use pdb it either does not set a breakpoint
sys.modules.pop('ArchWindow') # to unload, otherwise reloading Arch is no-op
importlib.reload(Arch)
EDIT:
Putting import pdb; pdb.set_trace() in the code works only slightly better. Although I can interact with pdb, it's really awkward because I write my commands in the console and get results in the report view. To make things worse pressing Enter sends a command to pdb but does not remove it from the command line.
Were you able to resolve this issue, steelman? I'm having the same issue on a debug build of freecad.
Zoltan wrote: ↑Wed Jul 07, 2021 10:22 am
I think the problem is that FreeCAD does not recognize the `--port` flag. How did you solve it?
I have not seen this issue, but I have only used the PyCharm debugging on Windows so far and also not tried with the latest FreeCAD version. I will try and see whether I can reproduce this behavior on Ubuntu.
Zoltan wrote: ↑Wed Jul 07, 2021 10:22 am
Another question: when you change the values of variables or create new objects in debug mode, are the changes reflected in the running FreeCAD instance the debugger is attached to? Thank you in advance.
When you edit the code of a workbench loaded in FreeCAD, the changes will not be reflected unless you reload the workbench. See the initial post of this thread for further details on reloading a workbench.
I think I figured out what is happening with PyCharm on Ubuntu. Usually, it should be possible to attach to processes with embedded Python, not just Python interpreters (PyCharm issue 14181). But it seems this is broken, since it currently tries to use the executable (e.g. FreeCAD) as Python interpreter to run the script that attaches to the process ("attach_pydevd.py"). The arguments (--port and --pid) would normally be handed to the script by the Python interpreter, but FreeCAD does not act like a Python interpreter and cannot digest this. There seems to be a similar issue with attaching to Maya on MacOS (PyCharm issue 49110). Maybe an older PyCharm version does not have this issue or we need to wait for Jetbrains to fix this.
Thank you @hlg for the explanation and that you communicated this issue towards JetBrains. A real solution would be a bug-fix, as I don't want to use an ancient version of PyCharm due to the useful new features and my plugins.