Skip to content

Debugger can't attach to Python project #960

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

Closed
hongyiqin opened this issue Feb 5, 2019 · 2 comments
Closed

Debugger can't attach to Python project #960

hongyiqin opened this issue Feb 5, 2019 · 2 comments

Comments

@hongyiqin
Copy link

hongyiqin commented Feb 5, 2019

Python Extention: 2019.1.0
Azure Functions: 0.13.1
CLI: 2.4.317

I just created a new azure function project (HttpTrigger) and then tried to debug it, I then got the error Failed to attach (connect ECONNREFUSED 127.0.0.1:9091)

From what I've gathered so far, it seems to indicate that python debugger tried to attach before function host had fully started. I've tried various suggested tweaks in launch.json and tasks.json but none have worked for me.

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach to Python Functions",
      "type": "python",
      "request": "attach",
      "port": 9091,
      "host": "localhost",
      "preLaunchTask": "runFunctionsHost"
    }
  ]
} 

tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "runFunctionsHost",
      "type": "shell",
      "osx": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func extensions install && pip install -r requirements.txt && func host start"
      },
      "windows": {
        "command": "${config:azureFunctions.pythonVenv}\\Scripts\\activate ; func extensions install ; pip install -r requirements.txt ; func host start"
      },
      "linux": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func extensions install && pip install -r requirements.txt && func host start"
      },
      "isBackground": true,
       "options": {
        "env": {
          "languageWorkers__python__arguments": "-m ptvsd --host 127.0.0.1 --port 9091"
        }
      }, 
       "problemMatcher": "$func-watch"
    },
    {
      "label": "funcPack",
      "type": "shell",
      "osx": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func pack"
      },
      "windows": {
        "command": "${config:azureFunctions.pythonVenv}\\Scripts\\activate ; func pack"
      },
      "linux": {
        "command": ". ${config:azureFunctions.pythonVenv}\\bin\\activate && func pack"
      },
      "isBackground": true
    }
  ]
}

Terminal printed out the message below before the error window popped up

Executing task: .env\Scripts\activate ; func extensions install ; pip install -r requirements.txt ; func host start

Terminal will be reused by tasks, press any key to close it.

@ejizba
Copy link
Contributor

ejizba commented Feb 5, 2019

@hongyiqin please see this comment and let me know if it helps your situation: #892 (comment)

@hongyiqin
Copy link
Author

@EricJizbaMSFT Thanks! Changing the separator from ; to && works!

Changing the terminal to Powershell doesn't work for python, the command to activate virtual env fails in powershell.

@vscodebot vscodebot bot locked and limited conversation to collaborators Mar 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants