How to debug a libadwaita python app?

I am making a gtk4/libadwaita app in python and packaging it in flatpak. How do I debug the python code running inside the flatpak sandbox container or even outside of it? The build system is meson/ninja and the IDE is vscode.
Let me know if you need further information.

I have no idea for vscode but i know gnome builder has a debug tool you can select in the build dropdown menu

Hey, thanks for the suggestion. Afaik debugging is not supported for languages other than C/C++/rust, all of which use gdb for that.
I tried running with debugger but am not able to set a breakpoint or even start the application when launching with debugger. start command in gdb does not help.
Any suggestions where to go from here would be quite helpful.

I’m developing an app with the same tools and, if there is a way to debug with flatpak+vscode, I don’t know. I’m commenting to receive notifications of this post in case someone comes up with a solution.

I haven’t tried this myself ( the time will come, I’m sure ), but if I were going to try to debug python apps inside flatpak, I’d install pudb inside flatpak, and then launch the app in that.

Thanks for bringing this up Dan! I did not try pudb myself but looks promising. However, this led me to start exploring more and also looking at how xdebug for php works, I discovered remote debugging for python. This is very useful for docker setups but flatpak apps behave almost the same way for this use case.

debugpy is the package I used and put these python lines to start listening for a remote debugger to attach to it.

debugpy.listen(('127.0.0.1', 9002))
debugpy.wait_for_client()
debugpy.breakpoint()

Flatpak shares the same network as the host using "--share=network" option so it should listen on the host. Now any debugger can be used to connect to it.
Note: debugpy.breakpoint() is the way to set breakpoints, the ui does not seem to work. Also, debugpy.wait_for_client() stops the code execution which will be the right time to start the external debugger. The code just goes on and does not stop at the breakpoints in its absence.

The vscode configuration for this is as follows:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Python Remote Attach",
			"type": "python",
			"request": "attach",
			"host": "127.0.0.1",
			"port": 9002,
		}
	]
}

Sources:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.