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

Error when trying to debug pyramid app on Windows #737

Closed
isoengas opened this issue Feb 9, 2018 · 7 comments · Fixed by #1504
Closed

Error when trying to debug pyramid app on Windows #737

isoengas opened this issue Feb 9, 2018 · 7 comments · Fixed by #1504
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug windows
Milestone

Comments

@isoengas
Copy link

isoengas commented Feb 9, 2018

Environment data

VS Code version: 1.20.0
Python Extension version: 2018.1.0
Python Version: 3.6.3
OS and version: Windows 10

Actual behavior

Using the default 'Python Pyramid' debug config throws an exception in the debug console:
ValueError: source code string cannot contain null bytes

Expected behavior

Debugger working

Not sure what additional information should be neccessary..

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug awaiting 1-verification area-debugging labels Feb 12, 2018
@brettcannon
Copy link
Member

I can verify this with the following example code by simply trying to run it under the debugger:

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/hello/{name}')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('localhost', 8080, app)
    server.serve_forever()

@Nicknk
Copy link

Nicknk commented Apr 24, 2018

Hello!
I have this problem with debug Pyramid application too. Before VSCode I have used PyCharm and have problem with pserve.exe in debugging. But it is correctly use pserve-script.py for start application in debug.
So I have hacked installed Python Extension (version: 2018.3.1) baseProvider.js - I have changed
const pserve = platformService.isWindows ? 'pserve.exe' : 'pserve'; to
const pserve = platformService.isWindows ? 'pserve-script.py' : 'pserve'; and now I can debug Pyramid Application.

But when started debug, application stop in 'version.py' on string 220, but after pressing F5 (Continue) application start and can be debugging.

May be my experiment help you check this bug.

Nicknk added a commit to Nicknk/vscode-python that referenced this issue Apr 24, 2018
@DonJayamanne DonJayamanne modified the milestones: May 2018, April 2018 Apr 25, 2018
@DonJayamanne
Copy link

DonJayamanne commented Apr 25, 2018

@Nicknk
Thanks for your PR, but I've started looking into this in a separate issue as well in #1483 and #1467.

@DonJayamanne DonJayamanne modified the milestones: April 2018, May 2018 Apr 25, 2018
@DonJayamanne
Copy link

Looking at the code on how pserve works, we'll need implement a different solution.
In the old debugger, we got things working by passing in the executable as the python program that needs to be run. It doesn't seem to work on Windows (as reported by OP and @Nicknk) and doesn't seem to work in the new (experimental) debugger either.

The code that bootstrap a pyramid application is found in bin/pserve, all this does is run the main method found in pyramid/scripts/pserve.py.
So the proper solution would be to simply run the above python file.

@Nicknk @isoengas What versions of Pyramid do you have installed?

@DonJayamanne
Copy link

@Nicknk until this is fixed you can change the launch.json as follows:

  • Remove the Pyramid setting from debugOptions
  • Change the program value to point to the file pyramid/scripts/pserve.py (please use the fully qualified path to the above file, found in the site_packages directory).

@isoengas
Copy link
Author

isoengas commented Apr 25, 2018

I can confirm that the solution proposed by @DonJayamanne is working on both the regular & experimental debuggers.

Thanks for your support!

I'm on pyramid 1.9.1, BTW and this is my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Pyramid",
            "type": "python",
            "request": "launch",
            "program": "<full path to pserve.py>",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            "debugOptions": [
                "RedirectOutput"
            ]
        },
        {
            "name": "Pyramid Experimental",
            "type": "pythonExperimental",
            "request": "launch",
            "program": "<full path to pserve.py>",
            "args": [
                "${workspaceFolder}/development.ini"
            ]
        }
    ]
}

@Nicknk
Copy link

Nicknk commented Apr 26, 2018

I can try solution - yes, it work with debuggers without problem.
@DonJayamanne, thanks for solution problem!

I am using Pyramid 1.9.1, VSCode 1.22.2 and Python 3.6.5 with virtual enviroment.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug windows
Projects
None yet
4 participants