Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disconnect command listener not working with debugpy and long-running programs #1264

Closed
abhinavnatarajan opened this issue Jun 12, 2024 · 1 comment

Comments

@abhinavnatarajan
Copy link

abhinavnatarajan commented Jun 12, 2024

Debug adapter definition and debug configuration

Using the following minimal configuration for nvim-dap with the debugpy adapter, I cannot get the disconnect listener to work correctly.

return {
	"mfussenegger/nvim-dap",
	keys = {
		{ "<Leader>Dt", function() require("dap").toggle_breakpoint() end, desc = "Toggle Breakpoint" },
		{ "<Leader>Ds", function() require("dap").continue() end, desc = "Start" },
		{
			"<Leader>Dd",
			function()
				require("dap").disconnect({ terminateDebuggee = false })
				require("dap").close()
			end,
			desc = "Disconnect debugger"
		},
	},
	config = function(_, opts)
		local dap = require("dap")

		dap.listeners.before.disconnect.cb =
				function()
					vim.notify("disconnected")
				end
		dap.listeners.before.event_terminated.cb = 
				function()
					vim.notify("terminated")
				end
		dap.listeners.before.event_exited.cb = 
				function()
					vim.notify("exited")
				end
		dap.adapters.python = {
					type = 'executable',
					command = vim.fn.exepath('debugpy-adapter'), -- debugpy installed via Mason
					options = {
						source_filetype = 'python',
					},
				},
		dap.configurations.python = {
			{
				type = 'python',
				request = 'launch',
				name = "Launch file",
				program = "${file}",
				python = '/usr/bin/python3'
			},
		}
	end
}

Debug adapter version

debugpy v1.8.1

Steps to Reproduce

Add a breakpoint on line 2 of the following file, and start the debugger.

import time
time.sleep(5) # set a breakpoint on this line
print('Nothing in particular')

When the debugger stops at the breakpoint, hit <leader>Dd to disconnect.

Expected Result

I should get a notification with the message disconnected.

Actual Result

No notification is raised, but I get [Process exited 0] in the DAP terminal.
The behaviour also depends on the sleep time. If I change the second line in the python file to time.sleep(0.1), the line Nothing in particular is printed to the DAP terminal before the process exit. I tried increasing the value of disconnect_timeout_sec in the adapter options, but this did not change the behaviour.

@mfussenegger
Copy link
Owner

That's up to the debug adapter. nvim-dap closes the connection after disconnect_timeout_sec to avoid waiting indefinitely. If the adapter doesn't send it there is nothing the client can do about it.

@mfussenegger mfussenegger closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants