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

Flask application process closes after a few seconds #85

Closed
delucca opened this issue Feb 14, 2023 · 4 comments
Closed

Flask application process closes after a few seconds #85

delucca opened this issue Feb 14, 2023 · 4 comments

Comments

@delucca
Copy link

delucca commented Feb 14, 2023

Hi everyone.

I'm trying to setup the debugger in my Flask application (using Poetry) but when I launch the configuration for some reason the Flask application closes after a few seconds.

Everything is working (besides that). The application is launching properly, but after it finishes bootstrapping the process is closed after a few seconds.

About my env:

  • I have one venv with debugpy and Poetry installed in it
  • This is my dap config:
local setup_ok_dap, dap = pcall(require, "dap")
local setup_ok_dap_python, dap_python = pcall(require, "dap-python")

if not setup_ok_dap_python then
	return
end

dap_python.setup("~/.python-venvs/bin/python")

table.insert(dap.configurations.python, {
	name = "Launch Flask server",
	type = "python",
	request = "launch",
	console = "integratedTerminal",
	cwd = "${workspaceFolder}",
	program = "${env:PYTHON_VENV_PATH}/bin/poetry",
	args = {
		"run",
		"flask",
		"--no-debug",
		"run",
	},
})

Note

python-venvs is where my Python venv is located (both Debugpy and Poetry are installed there)

When I run the application, this is what I get in the intergrated terminal:

 * Serving Flask app 'prprocessor'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit

[Process exited 247]

(the Process exited message takes a few seconds to appear)

Also, I've already tried to remove the --no-debug flag, the result is the same. And, of course, if I run the poetry run flask run outside of the debugger it works as expected (the server is launched and stays live)

@mfussenegger
Copy link
Owner

Could be related to multiprocessing, see mfussenegger/nvim-dap#858 (comment)

You could set export DEBUGPY_LOG_DIR=/tmp/debugpy/ in the terminal where you start neovim/debugpy to get debugpy logs for more insights.

@delucca
Copy link
Author

delucca commented Feb 15, 2023

@mfussenegger thanks for your quick response!

So, I did as you suggested and got the following log files:
debugpy.adapter-16432.log
debugpy.launcher-16440.log
debugpy.pydevd.16445.log
debugpy.server-16445.log

I'm not sure what those logs mean 🤔

@mfussenegger
Copy link
Owner

I tried a more minimal version and it works for me:

Setup:

python -m venv venv
venv/bin/python -m pip install Flask

Create vscode/launch.json:

{
   "version": "0.2.0",
   "configurations": [
       {
           "type": "python",
           "request": "launch",
           "name": "Flask",
           "module": "flask",
           "args": ["--app", "foo", "run"],
           "console": "integratedTerminal"
       }
   ]
}

Create foo.py:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "<p>Hello World</p>"

Maybe something odd going on with your use of poetry. I don't use it myself so I can't help you with that.
Maybe check the debugpy repository for more info on that.

@delucca
Copy link
Author

delucca commented Mar 2, 2023

@mfussenegger I was able to at least launch the debugger by running in a shell that has the venv activated (using poetry shell). But, whenever I try setting breakpoints I get a Server disconnected error, this is the log:

D+00004.256: Client[1] --> {
                 "seq": 5,
                 "type": "request",
                 "command": "setBreakpoints",
                 "arguments": {
                     "lines": [
                         8
                     ],
                     "source": {
                         "path": "/home/delucca/src/delucca/sandbox/poetry-debug-issue/poetry_debug_issue/__init__.py",
                         "name": "__init__.py"
                     },
                     "sourceModified": false,
                     "breakpoints": [
                         {
                             "line": 8
                         }
                     ]
                 }
             }

D+00004.257: /handling #5 request "setBreakpoints" from Client[1]/
             Client[1] <-- {
                 "seq": 11,
                 "type": "response",
                 "request_seq": 5,
                 "success": false,
                 "command": "setBreakpoints",
                 "message": "Server[1] disconnected unexpectedly"
             }

E+00004.266: /handling #5 request "setBreakpoints" from Client[1]/
             Handler 'Client.request' (file '/home/delucca/.python-venvs/lib/python3.10/site-packages/debugpy/adapter/components.py', line 134)
             couldn't handle #5 request "setBreakpoints" from Client[1]:
             Server[1] disconnected unexpectedly

Any ideas of what can I do?

I tried opening the issue on Poetry's repo, but they aren't very helpful.

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