Python System Debugging - SimDynamX/SpaceTeamsPRO GitHub Wiki
| Simulation Development Workflow → Python System Debugging |
|---|
Up to date for Platform 0.44.2
Written by Connor Jakubik
Prerequisites:
Python System Debugging
As a first resort, log messages and other forms of output should be used to inspect your code. There are however some programming issues that require a real IDE-based debugger to sort out. In normal programming, the IDE can be started in debugging mode and the code immediately stops at breakpoints and freezes execution on demand. Space Teams Python Systems are run as separate processes, which means there is a special procedure necessary to enter a debugging session where you can examine both the Python code and C++ objects behind it.
Extra per-install/per-update setup steps for Python debugger
-
Complete the C++ Developer Setup, as we will be using some tools from there.
-
Navigate to
<Install directory>/Compute_Server/externals -
Double click
py-install-x64-windows.exe -
Double click
py-install-x64-windows.exe -
Modify -
No changes needed on this screen;
Next -
Check
Download debugging symbolsandDownload debug binaries. -
Install
Setting up a simulation to be debugged
Python Systems are loaded and connected before the Lobby sim state is active. The Lobby sim state is the best time to attach a debugger to a Python System, as the Python interpreter can be waiting inside st.connect_to_sim() indefinitely during this state. This is also before the st.BeforeInit(function) and st.BeforeRuntime(function) functions has been run.
As of v0.44.2, the only ways to have the simulation not automatically continue from Lobby state are:
- Run the simulation from the Unreal Client and wait before clicking
Start Simulationin the role selection window. - Do your own sleep/waiting logic inside C++ or Python code.
Attaching to a Python System in the Visual Studio debugger
NOTE: Not VS Code; that would be a different process.
Once you have the simulation running (in Lobby state or later, such as Sync/Init/Runtime):
-
Open Visual Studio to the
<install dir>/Compute_Serverfolder as is explained in the C++ Developer Setup. -
Open the
Debugtab at the top of the window. -
Select
Attach to Process... -
Filter processes shown by typing
python.exein the top left field. -
There will be two processes for each Python System. You will probably need to expand the rightmost
Command Linesection of this window in order to see the name of the Python System. -
When you find the Python System you want to attach to, Select the version that has
TypeofPython, x64. -
For Python code debugging, ensure the
Code Typeis set to bothNativeandPython (native) code.WIP this may be slightly wrong; try
Python (native) codeandPythoninstead if you see issues.- Mostly for core developers, but also if you have a reason to examine the C++ objects, instead maybe pick
Nativeonly.
- Mostly for core developers, but also if you have a reason to examine the C++ objects, instead maybe pick
-
Attach
Now your debugger is attached to this Python System. Here are some ways to start debugging:
- Find your python file with
File->Open->File..., then add a breakpoint. - Press the pause button, change the active
ThreadtoMain Thread, and examine the Call Stack. Sometimes, this may be outside of your viewable code.
Extra Tips
- In Visual Studio, you can have a debugger attached to as many processes as you wish. This means you can have breakpoints in C++ and a number of Python Systems simultaneously.