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

Debugger stops on hot reload for Flask in debugger #2148

Closed
melvinkokxw opened this issue Jul 12, 2020 · 5 comments · Fixed by #2170
Closed

Debugger stops on hot reload for Flask in debugger #2148

melvinkokxw opened this issue Jul 12, 2020 · 5 comments · Fixed by #2170

Comments

@melvinkokxw
Copy link

Issue Type: Bug

Steps to reproduce problem:

  1. launch.json configuration as given below:
{
            "name": "Docker: Python - Flask",
            "type": "docker",
            "request": "launch",
            "preLaunchTask": "docker-run: debug",
            "python": {
                "pathMappings": [
                    {
                        "localRoot": "${workspaceFolder}/web/",
                        "remoteRoot": "/app"
                    }
                ],
                "host": "localhost",
                "port": 5000,
                "projectType": "flask",
            },
            "removeContainerAfterDebug": true}
        }

task.json given below:

{
			"type": "docker-build",
			"label": "docker-build",
			"platform": "python",
			"dockerBuild": {
				"tag": "<tag name removed>",
				"dockerfile": "${workspaceFolder}/web/Dockerfile",
				"context": "${workspaceFolder}/web/",
				"pull": true
			}
		},
		{
			"type": "docker-run",
			"label": "docker-run: debug",
			"dependsOn": [
				"docker-build"
			],
			"dockerRun": {
				"containerName": "<container name removed>",
				"env": {
					"FLASK_APP": "<app name removed>",
					"FLASK_ENV": "development",
					"FLASK_DEBUG": "1"
				},
				"volumes": [
					{
					  "containerPath": "/app", "localPath": "${workspaceFolder}/web/"
					},
				],
				"envFiles": [
					"${workspaceFolder}/web/.env"
				],
				"ports": [
					{
						"containerPort": 5000, "hostPort": 5000
					}
				]
			},
			"python": {
				"args": [
					"run",
					"--host",
					"0.0.0.0",
					"--port",
					"5000",
				],
				"module": "flask",
			}
		}
  1. Run debugger
  2. Make edit anywhere on a python file and save

Results

Expected results:
Flask hot reloads.

Actual results:
Last line in debug console is:

* Detected change in '/<python file name>.py', reloading

and then the debugger simply stops.

Apologies but I do not have a code snippet available for copying!

@bwateratmsft
Copy link
Collaborator

@melvinkokxw Thank you for the detailed information! I was able to reproduce your issue. When I set "removeContainerAfterDebug": false in launch.json, I was able to do hot reloading, however, it does require manually stopping the container after debugging is done (or else the next docker-run task fails because the container name is already in use).

I'll look to see what can be done in the code to mitigate the above shortcomings.

@melvinkokxw
Copy link
Author

@bwateratmsft Thank you for investigating the issue and identifying the cause. Setting "removeContainerAfterDebug": false in launch.json works for me.

Not setting that explicitly doesn't remove the container after debug, yet hot reload doesn't work. Is false the default value for removeContainerAfterDebug?

@bwateratmsft
Copy link
Collaborator

Hmm, it's supposed to be true by default, so if it's not specified it's still treated as true. I'll check on that as well.

@bwateratmsft
Copy link
Collaborator

@melvinkokxw I think I've found what went wrong and how to fix it, with hot reloading. The Python extension somewhat transparently makes two debug sessions--the outer "launch" session, and the inner "attach" session. When you save a file, the outer session is supposed to persist but the inner one is discarded. Our code for removing the container after debug was not able to tell the difference between those two--so when the inner one ended, it would remove the container.

I made a change so that we can tell them apart, and will not remove the container when the inner session ends.

As for the container not being removed when removeContainerAfterDebug was not explicitly set, I was not able to reproduce this. However, there have been some VSCode issues lately where changes in launch.json or tasks.json don't get picked up, so if it was false and then you removed it, it's possible you hit that bug--and VSCode thought it was still false.

@bwateratmsft bwateratmsft self-assigned this Jul 16, 2020
@bwateratmsft bwateratmsft added this to the 1.5.0 milestone Jul 16, 2020
@bwateratmsft bwateratmsft removed their assignment Jul 20, 2020
@vscodebot vscodebot bot locked and limited conversation to collaborators Aug 31, 2020
@bwateratmsft
Copy link
Collaborator

This has been fixed in Docker extension version 1.5.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants