Help set up VSCode debugging + Pyramid App + docker

57 views
Skip to first unread message

Bach

unread,
Oct 4, 2020, 11:20:28 PM10/4/20
to pylons-discuss
Hi everyone,

been trying to setup Visual Studio Code to debug my Pyramid App running inside a docker container.

Does anyone have any sample files to share where you got that setup to work:
- Dockerfile
- docker-compose.yml
- launch.json 

I initially setup an environment as described in this video, but the example uses Flask and not pserve:

Any help or direction will be really appreciated!

thanks

Steve Piercy

unread,
Oct 4, 2020, 11:35:43 PM10/4/20
to pylons-...@googlegroups.com, Bach
Check out deformdemo. It might help you get part of the way there.

https://github.com/Pylons/deformdemo

--steve

Bach

unread,
Oct 5, 2020, 6:31:26 PM10/5/20
to pylons-discuss
Thanks Steve I've had a good start following that youtube video and looking through deformdemo (thanks for the pointer)
But I can't get the ptvsd debugger to stop at breakpoints.. It's like it attaches, but is not serving the app.. pserve is. So can't stop on breakpoints.

Perhaps I need to move to debugpy instead..

Dockerfile


docker-compose.yml


launch.js

Steve Piercy

unread,
Oct 5, 2020, 7:29:52 PM10/5/20
to pylons-...@googlegroups.com, Bach
I have not had success using the PyCharm debugger with Docker. Supposedly it is possible, but I have not found the magic combination of switches to flip and knobs to turn.

--steve


On 10/5/20 3:31 PM, Bach wrote:
> Thanks Steve I've had a good start following that youtube video and looking through deformdemo (thanks for the pointer)
> But I can't get the *ptvsd* debugger to stop at breakpoints.. It's like it attaches, but is not serving the app.. pserve is. So can't stop on breakpoints.
>
> Perhaps I need to move to debugpy <https://github.com/microsoft/debugpy> instead..
>
> *Dockerfile*
>
>
> docker-compose.yml
>
>
> launch.js
>
>
>
>
>
> On Monday, 5 October 2020 at 14:35:43 UTC+11 Steve Piercy wrote:
>
> Check out deformdemo. It might help you get part of the way there.
>
> https://github.com/Pylons/deformdemo
>
> --steve
>
>
> On 10/4/20 8:20 PM, Bach wrote:
> > Hi everyone,
> >
> > been trying to setup Visual Studio Code to debug my Pyramid App running inside a docker container.
> >
> > Does anyone have any sample files to share where you got that setup to work:
> > - Dockerfile
> > - docker-compose.yml
> > - launch.json 
> >
> > I initially setup an environment as described in this video, but the example uses Flask and not pserve:
> > https://www.youtube.com/watch?v=b78Tg-YmJZI
> >
> > Any help or direction will be really appreciated!
> >
> > thanks
>
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com <mailto:pylons-discus...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/8980fc68-155f-4348-8109-9bd5a9e8b055n%40googlegroups.com <https://groups.google.com/d/msgid/pylons-discuss/8980fc68-155f-4348-8109-9bd5a9e8b055n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Andrew Free

unread,
Oct 5, 2020, 7:31:31 PM10/5/20
to pylons-...@googlegroups.com, bac...@gmail.com
It wouldn’t be integrated into vscode but you could use 
https://pypi.org/project/remote-pdb/ to connect to a “remote” process like something within a container. 

— Andrew Free

-- 
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/8980fc68-155f-4348-8109-9bd5a9e8b055n%40googlegroups.com.

Michael Merickel

unread,
Oct 5, 2020, 7:48:10 PM10/5/20
to pylons-...@googlegroups.com
The issue that makes pserve different from Marcel Demper's example is that `pserve --reload` uses a multiprocess model (via hupper) to spawn your code in a subprocess. If you run without `--reload` things will work as expected.

If you want `--reload` to work, you will need to run ptvsd inside your process instead of externally via something like:

    if I_SHOULD_ATTACH_TO_VSCODE:
        try:
            import ptvsd
        except ModuleNotFoundError:
            raise RuntimeError('ptvsd is not installed')

        print("Waiting for debugger attach ...", file=sys.stderr)
        ptvsd.enable_attach(address=('0.0.0.0', 5678), redirect_output=True)
        ptvsd.wait_for_attach()

You could run this inside your __init__.py or somewhere else that is executed inside the subprocess.

- Michael

Bach

unread,
Oct 6, 2020, 12:05:36 AM10/6/20
to pylons-discuss
Thanks a lot Michael that's perfect!!
I have removed --reload and everything worked as expected!

now onto trying your example to get --reload working.
Thanks again guys I really appreciate.

Bach

Reply all
Reply to author
Forward
0 new messages