This is a working proof of concept for debugging python code executing inside of Touchdesigner. Can trigger breakpoints and watch the execution state (inspect variables). Tested in Touchdesigner 2022.31030.
π½ You can alternatively follow this video tutorial.
-
π Install
debugpy
in Touchdesigner's python installation:-
In Touchdesigner's textport execute:
print(sys.exec_prefix)
-
π Go to the path in the output and open a
cmd
console there. Run:python -m pip install debugpy
-
β If there is an error saying
No module named pip
, you can use this solution. Translated to Windows it would be:-
π Go to the link in a browser and save the file (
ctrl+s
). -
π Put it in the path where the
python.exe
is located (output of step 1.1). -
β¨οΈ On a command prompt located there run:
arduinoCopy code python get-pip.py
-
π Restart the console and try step 1.2 again.
-
-
-
π£οΈ Touchdesigner paths have to be replicated in Windows file system for breakpoints set in the UI to trigger:
- π Put the
TD_debugger
folder directly in your C drive. - π Put the
.vscode
insideTD_debugger
directly in your C drive.
You can skip step 2 but you are going to have to set the breakpoints explicitly in the code with the command
debugpy.breakpoint()
. If you choose to use it like this, make sure that the pathMappings section in your launch.json is like this:"pathMappings": [{ "localRoot": "${workspaceFolder}", "remoteRoot": "c:" }],
Where the letter of the
remoteRoot
has to match the drive letter of where you have theDebugger.toe
. - π Put the
-
On a terminal run
setx DEBUGPY_PROCESS_SPAWN_TIMEOUT 90
to increase the time vscode is going to wait for the debugger to connect to the server. Thanks to @AlphaMoonbaseBerlin for figuring this out!
-
π₯οΈ Open Visual Studio Code in your C drive.
-
π¨ Open the
Debugger.toe
in TouchDesigner. -
πΉοΈ Connect vscode by going to the Debug tab and pressing the play button. A dropdown should open, look for
TouchDesigner.exe
and select that process. It takes around 35 seconds for the debugger to connect the first time.
π If the bottom bar turns orange it means that it was able to connect successfully. Add a breakpoint in line 15 in vscode and trigger a Jump in the exampleExtension using the jump pulse. Vs code should stop at that line and allow you to inspect the state of the program in the left column.
I think that vscode injects a dll in the running Touchdesigner process which launches a debugpy server to which the vscode debugger connects to. By default it times out, that is why we have to increase the timeout time
- πFigure out how to make the breakopoints set in the vscode UI work with this. I think the problem is related to the paths because when we move the whole project directly to the C drive and the paths are equal in Touchdesigner and in Windows, it works.
Link to discussion on Derivative's forum