popmonkey
popmonkey

Reputation: 51

pserve exits immediately after being launched in the VSCode python debugger

I have a python-2.7 env Pyramid 1.4 application that I've been developing on OS X (10.14.5 as of this writing). Once the env is activated i can start pserve from the command line and test the app. I want to be able to debug from within VSCode. I've configured the debugger with the Pyramid setup in launch.json:

        {
            "name": "Python: Pyramid Application",
            "type": "python",
            "request": "launch",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            "pyramid": true,
            "jinja": true
        }

Whenever I start the Debugger from within VSCode (F5) all the expected commands run and they look legitimate:

$ source /my/app/path/env/bin/activate
$ cd /my/app/path ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /my/app/path/env/bin/python /my/home/.vscode/extensions/ms-python.python-2019.4.12954/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63836 /my/app/path/env/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/scripts/pserve.py /my/app/path/development.ini 

There are no errors but the launcher command exits and the debugger never activates. pserve is not running in the background. the debugging toolbar briefly appears at the top of the editor window but then disappears after less than a second (so i imagine there's a brief debugging sessions that ends for some reason)

i've tried changing options in my development.ini to use a different pyramid server main

[server:main]
; use = egg:waitress#main
use = egg:pyramid#wsgiref
host = 0.0.0.0
port = 6666

no difference

there's very little information on the VSCode python pages.

I'd be fine adding code to the files i need to debug (my fallback is pdb) but would love to take advantage of the awesome debugger in VSCode.

Note that if i manually (instead of pressing F5) enter

 cd /my/app/path ; env PYTHONIOENCODING=UTF-8 PYTHONUNBUFFERED=1 /my/app/path/env/bin/python /my/home/.vscode/extensions/ms-python.python-2019.4.12954/pythonFiles/ptvsd_launcher.py --default --client --host localhost --port 63836 /my/app/path/env/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/scripts/pserve.py /my/app/path/development.ini

in the terminal - i get a socket.error: [Errno 61] Connection refused i assume because VSCode's debugger has already shut down.

if i run the following in the same VSCode terminal window

/my/app/path/env/lib/python2.7/site-packages/pyramid-1.4-py2.7.egg/pyramid/scripts/pserve.py /my/app/path/development.ini

my server starts fine and serves requests. so it seem like something to do with the ptvsd launcher.

any ideas?

Upvotes: 1

Views: 726

Answers (1)

popmonkey
popmonkey

Reputation: 51

the solution i came up with (which works) is to change my pyramid setup in launch.json to looks like this:

        {
            "name": "Python: Pyramid Application",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/env/bin/pserve",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            // "pyramid": true
            // "jinja": true
            "debugOptions": [
                "RedirectOutput",
            ]        
        }

basically i am forcing the debugger to launch pserve with a manual setup. this works, i'm able to hit breakpoints and see variable values.

Upvotes: 2

Related Questions