Terminology used in the debugpy
documentation
#1688
Replies: 3 comments 2 replies
-
The IDE can either open a port itself (and then debugpy.connect would be used) or the IDE can connect to a port created by debugpy (debupy.listen). This proposal on web assembly actually has a diagram:
There are actually multiple processes involved when using debugpy. There's the VS code process (DAP client), the Debug adapter (debugpy.adapter subfolder), and the app itself. The debug adapter is listening for DAP requests and then it forwards the necessary messages to the debugpy code injected into the app. The adapter process is there to manage the lifetime of the app (like being able to stop debugging by killing the process). The |
Beta Was this translation helpful? Give feedback.
-
That diagram is misleading. Each box in that diagram is not a process. Debugpy starts 3 processes when you debug from VS code:
Maybe it would be better to understand why you want to know how debugpy works? What are you using it for? You seem interested in the server/client aspect of debugpy. Are you trying to do something remote? |
Beta Was this translation helpful? Give feedback.
-
Okay so I'll just repeat what you described in order to make sure I understand it. You want to debug an app which is launched by another app - a template app as you called it. The command line args to the launched app keep changing so you can't just launch it yourself? My first thought is why not debug the template app itself? Maybe it's not python code. Debugpy can debug child processes but it will only work if the parent process is also python. My second thought is to do to what you're describing. Have your app wait for the debugger to attach, maybe with an environment variable or something that dictates waiting. I'll try answering your other questions:
import debugpy
debugpy.listen(5679) # listen for incoming DAP client connections (but open the port here)
debugpy.wait_for_client() # wait for a client to connect
print("After attach") Then in VS code use this launch.json {
"name": "Python Debugger: Attach to listening debugpy",
"type": "debugpy",
"request": "attach",
"connect": {
"port": 5679
},
}, That works for me to repeatedly attach and disconnect from a process. Every time the process shuts down, the port is freed so it can be used again. |
Beta Was this translation helpful? Give feedback.
-
I have been struggling to understand the terminology which is being used in documentation for the
debugpy
package, and I would really appreciate if you could help me understand it a bit better.To my understanding, there are three component which are involved in the debugging-process when you run the debugger in an IDE which uses the debugging-adapter-protocol (i.e. DAP):
I think that the following screenshot describes well the relation between the three terms I described above:
Note: I am new to DAP, and this is my understanding of the DAP protocol, and how modern IDE-s (like VS Code, or PyCharm) implement the debugging functionality. The knowledge I have about DAP gained from the following article: the article about DAP
The terms which appear in the documentation of the package
debugpy
(mostly in the descriptions of functions defined in debugpy) that I have a problem with understanding are:Can you please help me map these terms to the ones which are given in the explanation which I gave above, or an additional explanation if they refer to something completely different?
I am guessing correctly that the "DAP-client" refers to the IDE itself, and that "debug-server" refers to the actual debugger for a certain programming-language. However, even I am guessing correctly, I lack the basic understanding of how to what do the following descriptions of functions refer to:
debugpy.connet(...)
- Connect the debug-server to a DAP-client that is waiting for incoming connections.debugpy.listen(...)
- Set up the debug-server to listen for incoming DAP-client connections.What does it meant that "a DAP-client is waiting for an incoming connection"? If "DAP-client" refers to the IDE, how can the IDE be waiting for a connection?
What does it mean that "a debugging-server is to listen to an incoming DAP-client connection"? If "debug-server" refers to an actual debugger of a programming-language, how can the actual debugger be waiting for a connection?
Thank you in advance for your help.
Beta Was this translation helpful? Give feedback.
All reactions