mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django and multiprocess

Mte90 opened this issue · comments

With this config:


        {
            type = 'python',
            request = 'launch',
            name = 'DAP Django',
            program = vim.loop.cwd() .. '/manage.py',
            args = {
                'runserver',
            },
            justMyCode = true,
            django = true,
            console = "integratedTerminal",
        },

I don't get the webserver running on 127.0.0.1:8000

I see debugpy running:
image

Also the terminal in the dap-ui is empty.

dap.log has this:

[ INFO ] 2024-01-22T12:22:05Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"ptvsd"
[ INFO ] 2024-01-22T12:22:05Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"debugpy"
[ INFO ] 2024-01-22T12:22:06Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"ptvsd"
[ INFO ] 2024-01-22T12:22:06Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"debugpy"
[ WARN ] 2024-01-22T12:22:06Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1000 ]	"No event handler for "	{
  body = {
    host = "127.0.0.1",
    port = 59717
  },
  event = "debugpyWaitingForServer",
  seq = 4,
  type = "event"
}

Trying to replicate the command:

.venv/bin/python -m debugpy  --listen 5678 --wait-for-client  ./manage.py runserver
0.00s - Debugger warning: It seems that frozen modules are being used, which may
0.00s - make the debugger miss breakpoints. Please pass -Xfrozen_modules=off
0.00s - to python to disable frozen modules.
0.00s - Note: Debugging will proceed. Set PYDEVD_DISABLE_FILE_VALIDATION=1 to disable this validation.

I guess that the command is incomplete because I am not sharing the django parameter as example, but the problem is that the terminal inside it is empty so it is difficult to understand the real issue.

I'm not sure about nvim-dap-ui, but without it you should have a terminal window open up with the server running.

The warning in regards to debugpyWaitingForServer should be harmless. It's just an info and there should be more messages afterwards if you set the log level to trace.

Here's how it looks like for me with a bare django-admin startproject mysite project and a .vscode/launch.json:

recording

Nope In my case is still an empty terminal:

immagine

With on my lua settings

        {
            type = 'python',
            request = 'launch',
            name = 'DAP Django',
            program = '${workspaceFolder}/manage.py',
            args = {
                'runserver', 
            },
--             justMyCode = true,
            django = true,
            console = "integratedTerminal", 
        },

If I left no-reload I get the usual Django prompt like in your screen.

Setting the log level to trace:

[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1366 ]	"Spawning debug adapter"	{
  args = { "-m", "debugpy.adapter" },
  command = "/home/www/myproject/.venv/bin/python",
  type = "executable"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  arguments = {
    adapterID = "nvim-dap",
    clientID = "neovim",
    clientName = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "it_IT.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.8.0"
    },
    output = "ptvsd"
  },
  event = "output",
  seq = 1,
  type = "event"
}
[ INFO ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"ptvsd"
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.8.0"
    },
    output = "debugpy"
  },
  event = "output",
  seq = 2,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  body = {
    exceptionBreakpointFilters = { {
        default = false,
        description = "Break whenever any exception is raised.",
        filter = "raised",
        label = "Raised Exceptions"
      }, {
        default = true,
        description = "Break when the process is exiting due to unhandled exception.",
        filter = "uncaught",
        label = "Uncaught Exceptions"
      }, {
        default = false,
        description = "Break when exception escapes into library code.",
        filter = "userUnhandled",
        label = "User Uncaught Exceptions"
      } },
    supportsClipboardContext = true,
    supportsCompletionsRequest = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsDebuggerProperties = true,
    supportsDelayedStackTraceLoading = true,
    supportsEvaluateForHovers = true,
    supportsExceptionInfoRequest = true,
    supportsExceptionOptions = true,
    supportsFunctionBreakpoints = true,
    supportsGotoTargetsRequest = true,
    supportsHitConditionalBreakpoints = true,
    supportsLogPoints = true,
    supportsModulesRequest = true,
    supportsSetExpression = true,
    supportsSetVariable = true,
    supportsStepInTargetsRequest = true,
    supportsTerminateRequest = true,
    supportsValueFormattingOptions = true
  },
  command = "initialize",
  request_seq = 1,
  seq = 3,
  success = true,
  type = "response"
}
[ INFO ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"debugpy"
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  arguments = {
    args = { "runserver" },
    console = "integratedTerminal",
    django = true,
    name = "DAP Django",
    program = "/home/www/myproject/manage.py",
    request = "launch",
    type = "python"
  },
  command = "launch",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  arguments = {
    args = { "/home/www/myproject/.venv/bin/python", "/home/www/myproject/.venv/lib/python3.11/site-packages/debugpy/launcher", "47815", "--", "/home/www/myproject/manage.py", "runserver" },
    cwd = "/home/www/myproject",
    env = vim.empty_dict(),
    kind = "integrated",
    title = "Python Debug Console"
  },
  command = "runInTerminal",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:208 ]	"run_in_terminal"	{
  args = { "/home/www/myproject/.venv/bin/python", "/home/www/myproject/.venv/lib/python3.11/site-packages/debugpy/launcher", "47815", "--", "/home/www/myproject/manage.py", "runserver" },
  cwd = "/home/www/myproject",
  env = vim.empty_dict(),
  kind = "integrated",
  title = "Python Debug Console"
}
[ DEBUG ] 2024-01-23T15:38:23Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1706 ]	"response"	{
  body = {
    processId = 85906
  },
  command = "runInTerminal",
  request_seq = 4,
  seq = 3,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  event = "initialized",
  seq = 5,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  arguments = {
    filters = { "uncaught" }
  },
  command = "setExceptionBreakpoints",
  seq = 4,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  command = "setExceptionBreakpoints",
  request_seq = 4,
  seq = 6,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  command = "configurationDone",
  seq = 5,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  command = "configurationDone",
  request_seq = 5,
  seq = 7,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  command = "launch",
  request_seq = 2,
  seq = 8,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  body = {
    isLocalProcess = true,
    name = "/home/www/myproject/manage.py",
    pointerSize = 64,
    startMethod = "launch",
    systemProcessId = 85911
  },
  event = "process",
  seq = 9,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  body = {
    reason = "started",
    threadId = 1
  },
  event = "thread",
  seq = 10,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	1	{
  arguments = {
    configuration = {
      connect = {
        host = "127.0.0.1",
        port = 50305
      },
      console = "integratedTerminal",
      django = true,
      isOutputRedirected = false,
      name = "Subprocess 85934",
      program = "/home/www/myproject/manage.py",
      python = { "/home/www/myproject/.venv/bin/python" },
      subProcessId = 85934,
      type = "python"
    },
    request = "attach"
  },
  command = "startDebugging",
  seq = 11,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1366 ]	"Spawning debug adapter"	{
  args = { "-m", "debugpy.adapter" },
  command = "/home/www/myproject/.venv/bin/python",
  type = "executable"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  arguments = {
    adapterID = "nvim-dap",
    clientID = "neovim",
    clientName = "neovim",
    columnsStartAt1 = true,
    linesStartAt1 = true,
    locale = "it_IT.UTF-8",
    pathFormat = "path",
    supportsProgressReporting = true,
    supportsRunInTerminalRequest = true,
    supportsStartDebuggingRequest = true,
    supportsVariableType = true
  },
  command = "initialize",
  seq = 1,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:24Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1706 ]	"response"	{
  command = "startDebugging",
  request_seq = 11,
  seq = 6,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.8.0"
    },
    output = "ptvsd"
  },
  event = "output",
  seq = 1,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  body = {
    category = "telemetry",
    data = {
      packageVersion = "1.8.0"
    },
    output = "debugpy"
  },
  event = "output",
  seq = 2,
  type = "event"
}
[ INFO ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"ptvsd"
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  body = {
    exceptionBreakpointFilters = { {
        default = false,
        description = "Break whenever any exception is raised.",
        filter = "raised",
        label = "Raised Exceptions"
      }, {
        default = true,
        description = "Break when the process is exiting due to unhandled exception.",
        filter = "uncaught",
        label = "Uncaught Exceptions"
      }, {
        default = false,
        description = "Break when exception escapes into library code.",
        filter = "userUnhandled",
        label = "User Uncaught Exceptions"
      } },
    supportsClipboardContext = true,
    supportsCompletionsRequest = true,
    supportsConditionalBreakpoints = true,
    supportsConfigurationDoneRequest = true,
    supportsDebuggerProperties = true,
    supportsDelayedStackTraceLoading = true,
    supportsEvaluateForHovers = true,
    supportsExceptionInfoRequest = true,
    supportsExceptionOptions = true,
    supportsFunctionBreakpoints = true,
    supportsGotoTargetsRequest = true,
    supportsHitConditionalBreakpoints = true,
    supportsLogPoints = true,
    supportsModulesRequest = true,
    supportsSetExpression = true,
    supportsSetVariable = true,
    supportsStepInTargetsRequest = true,
    supportsTerminateRequest = true,
    supportsValueFormattingOptions = true
  },
  command = "initialize",
  request_seq = 1,
  seq = 3,
  success = true,
  type = "response"
}
[ INFO ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:744 ]	"Telemetry"	"debugpy"
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1676 ]	"request"	{
  arguments = {
    connect = {
      host = "127.0.0.1",
      port = 50305
    },
    console = "integratedTerminal",
    django = true,
    isOutputRedirected = false,
    name = "Subprocess 85934",
    program = "/home/www/myproject/manage.py",
    python = { "/home/www/myproject/.venv/bin/python" },
    request = "attach",
    subProcessId = 85934,
    type = "python"
  },
  command = "attach",
  seq = 2,
  type = "request"
}
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  body = {
    host = "127.0.0.1",
    port = 56691
  },
  event = "debugpyWaitingForServer",
  seq = 4,
  type = "event"
}
[ WARN ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:1000 ]	"No event handler for "	{
  body = {
    host = "127.0.0.1",
    port = 56691
  },
  event = "debugpyWaitingForServer",
  seq = 4,
  type = "event"
}
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  command = "attach",
  request_seq = 2,
  seq = 5,
  success = true,
  type = "response"
}
[ DEBUG ] 2024-01-23T15:38:25Z+0100 ] /home/mte90/.vim/plugged/nvim-dap/lua/dap/session.lua:950 ]	2	{
  event = "terminated",
  seq = 6,
  type = "event"
}

So just investigating in the code of nvim-dap the process get spawned but there isn't any track of the various commands output if not in a window inside neovim.
It is possible to get it in a file to investigate what is the issue? because after digging seems something that doesn't start right in Django but without the output it isn't impossible to debug it.

The log generated is just the response from the session but doesn't include the command spawned output and a debug is very difficult.
Also maybe there is a way to run tests locally with my django settings just to get some info? because right now without any error is very impossible to do anything to understand what is happening.

So if I try to crash django I get the output in the terminal window in nvim-dap otherwise I don't get any output like the one you mentioned.
I tried with the parameters in the lua table to get the django output in a file but doesn't work.

The process is running but I am not able to see the output, the log file include only the output from the request to the DAP Server and the various parameters.
Right now for me is impossible to use DAP with Django (with poetry).

I tried also with a clean project django-admin startproject mysite but it is the same.
With that I didn't created any venv as I have debugpy etc installed also on host but anyway there isn't any output after launching the session (using the lua settings)

image

As I am not getting help I am trying alone to understand what is happening.

I see that debugpy is started with telnet (from nvim):

telnet localhost 5678
Trying ::1...
Connection failed: Connessione rifiutata
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Content-Length: 137

{"seq": 1, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "ptvsd", "data": {"packageVersion": "1.8.1"}}}Content-Length: 139

{"seq": 2, "type": "event", "event": "output", "body": {"category": "telemetry", "output": "debugpy", "data": {"packageVersion": "1.8.1"}}}

I don't have this kind of content in the dap.log so my guess is that the client doesn't connect at all to the running instance that starts.
I wasn't able to find another dap client to understand what is happening.

I tried also with launch.json but it wasn't found from neovim.

I tried with a python script:


    import time
    import random
    import debugpy

    (host, port) = debugpy.listen(5678)

    print(f'Debugpy: Listening on {host}:{port}')

    if __name__ == '__main__':
        while True:
            x, y = random.randint(1, 10), random.randint(1, 10)
            print(f'The sum of {x} and {y} is {x + y}.')
            time.sleep(1)

Running and connecting also on only attach mode and doesn't work. In this case in the host as I have debugpy installed globally but the script doens't stop.
Also with Kate editor that has the DAP debugger isn't working too so there is something generally in my machine that doesn't let the client to connect to the running debugpy instance.

Ok so I found a fix, activating the venv fixes the issues.
I was using poetry and the venv it was passed rightly as path for python but doesn't seems:
image

So I can check now what is happening better.