question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode + debugging + poetry

See original GitHub issue

Hi,

we use poetry and I like to use my poetry scripts as entry points for the debugging in vscode. Therefore, we use following vscode launch.json configurations:

{
    "configurations": [
        {
            "name": "poet_####",
            "type": "python",
            "request": "launch",
            "module": "poetry",
            "subProcess": true,
            "args": [
                "run",
                "###name###",
            ],
            "console": "integratedTerminal",
            "justMyCode": true,
            "cwd": "${workspaceFolder}",
            "envFile": "",
            "env": {},
        },
    ]
}

The issue is that the debugging starts BUT exits early (after some seconds). In the middle of the process, everything stops. This is the case for all our code which is run via poetry.

If we run the python code manually without the poetry run command, but in a poetry shell with python main.py, the debugging works flawlessly.

If I run in a shell manually poetry run ###name### it also works flawlessly.

In principle the debugging with poetry seems to work. It stops at breakpoints and shows error msgs etc. But as mentioned, shortly after that the whole execution stops and I am out of the debugging and the process itself.

Anyone an idea what causes the early exiting?

VSCode: 1.65.2 Poetry (systemwide): 1.1.13 Poetry python: poetry: 1.1.13 poetry-core: 1.0.8

  • [ x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x] I have searched the documentation and believe that my question is not covered.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

8reactions
lucasvazqcommented, Jul 8, 2022

I FOUND A SOLUTION 😄 🥳

Pre requirements

Poetry creates environments in a cache folder. On my OS (Manjaro), environments are created in ~/.cache/pypoetry/virtualenvs/. These environments do not have constant names that are easy to identify. For example, my “pizzas” project, has the environment folder defined with the name “pizzas-wQgq9NEZ-py3.10”

So, first of all, this needs to be resolved. We need a more consistent and specific environment path. What you have to do is find and remove the environment of your project.

In my case I run:

rm -rf ~/.cache/pypoetry/virtualenvs/pizzas-wQgq9NEZ-py3.10

After that, you need to specify a new environment directory:

poetry config virtualenvs.in-project true

This will create a new .venv file within your project. You can ignore it with .gitignore.

Because we created a new environment, we have to install the dependencies again. Execute the following command at the root of your project:

poetry install

Config

With the prerequisite fixed, you can use a configuration similar to the following:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Pizzas service",
            "type": "python",
            "request": "launch",
            "pythonPath": "${workspaceFolder}/backend/pizzas/.venv/bin/python",
            "cwd": "${workspaceFolder}/backend/pizzas",
            "module": "uvicorn",
            "justMyCode": false,
            "args": [
                "src.main:app",
                "--host",
                "0.0.0.0",
                "--port",
                "8000",
                "--reload"
            ]
        }
    ]
}
2reactions
DaviYokogawacommented, Jul 12, 2022

@lucasvazq your solution solve my problems, congrats bro!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python project created using Poetry: how do I debug it in ...
For Visual Studio Code, you could try this: add an __init__.py file in the sub-directory my_project; in the .vscode directory, ...
Read more >
Debug Django with VS Code and Poetry in macOS
Debug Django with VS Code and Poetry in macOS ... VS Code has a great debugger & Python plugin that works perfectly with...
Read more >
VS Code and poetry - openQA bites
Launch project with the debugger. TL;DR. Create the poetry project: poetry init; Determine the poetry virual environment path using poetry shell ...
Read more >
Python projects with Poetry and VSCode Part 2
The first command, poetry shell , will spawn us inside our virtual environment, and code . will open the current folder inside VSCode....
Read more >
Configuring Poetry in Visual Studio Code - Olav Lindekleiv
This weekend I tried Poetry as an alternative to Pipenv, so here's how you set it up in VS Code. After setting up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found