Integrating Python Debugging with Visual Studio Code in a Custom Application

I’ve integrated Python directly into my application, running it within the same process by loading Python’s relevant libraries. I’m looking to debug Python code through my application’s Python interface using Visual Studio Code. After examining the debugpy module’s source code, which facilitates Python debugging in VSCode, I’m seeking guidance on how to configure my application.

Specifically, I want to be able to attach to my application’s PID using VSCode, ensuring that code executions triggered by my application will pause at breakpoints set in VSCode. How can I achieve this? How does attaching to a PID, getting its corresponding port number, interaction with VSCode, debugpy and Python work?