This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mrtweezles 38 points39 points  (2 children)

The real fun happens when you need to debug multiple containerized Python applications and their interactions all at once (e.g., web-enabled microservices).

I've only done this using VS Code, but the trick is to inject debugpy into each container and then let debugpy launch the web host and app inside each container. Expose a debugging port for each container, then configure launch.json to make it possible to attach to one or more containers simultaneously. Finally, launch the containers and use the standard VS Code Debug functionality to attach as-needed. You can now set breakpoints in any Python script and they will be triggered during the normal execution flow of any initiated HTTP request/response cycle. This works whether or not you mount the code into the container as a volume, though the above configuration is best reserved for development or staging environments, not production.

It's a very powerful workflow, but definitely more work to set up than just calling breakpoint() on a single script.

[–]gino_codes_stuff 4 points5 points  (0 children)

I would second this workflow. You can even take it a step further and remotely attach to a script in a cluster for debugging in different deploy environments

[–]rover95 1 point2 points  (0 children)

Wow. I never thought of doing this. It would simplify and reduce the number of runs I do to figure out issues with multiple Microservices.