Config: Add debugpy support and update Docker configuration#1356
Config: Add debugpy support and update Docker configuration#1356drikusroor wants to merge 3 commits intodevelopfrom
debugpy support and update Docker configuration#1356Conversation
BeritJanssen
left a comment
There was a problem hiding this comment.
I'm personally fine with just using vanilla pdb, but anything that makes dev life easier is certainly worth adding. I do hope there's a way to add this without having to adjust the docker-compose file every time we want to run the debug server. BTW, I would expect the current state of docker-compose.yaml (i.e., having the backend image set to base and calling the debugpy function) to not run?
That's right, the |
73c8e64 to
1fc16fb
Compare
| command: > | ||
| bash -c "python manage.py migrate && | ||
| python manage.py bootstrap && | ||
| ${DEBUG_COMMAND:-python manage.py runserver 0.0.0.0:8000}" |
There was a problem hiding this comment.
So this part runs the debug command as configured in your .env file if configured and runs the normal startup command if there is no debug command configured.
b9145d4 to
fa1c44e
Compare
debugpy support and update Docker configuration
| if not is_debugpy_running(5678): | ||
| print("Starting debugpy on port 5678 🐛") | ||
| debugpy.listen(("0.0.0.0", 5678)) | ||
| else: | ||
| print("Debugpy is already running on port 5678 👍") |
There was a problem hiding this comment.
This check has been added since the django server (but not the container) will restart once you change a file. The debug server will spawn a separate process as far as I understood and won't get terminated whenever the django server restarts.
018eb18 to
7ea8ef7
Compare
Integrate debugpy for remote debugging and adjust Docker settings to facilitate its use, including necessary configurations in the Dockerfile and Docker Compose. It will allow you to do remote debugging from VS Code, using the Python and/or Python Debugger extensions.
It adds a Docker image variant for the backend; the
debugimage. You can (temporarily) configure yourdocker-compose.yamlfile to use this image instead of thebaseimage (here). This image starts up a debugging server on port5678next to the Django server (that runs on port8000).Then, with the use of the (now un-ignored by
.gitignore) launch.json file, you can attach VS Code to the debugging server that is now running on5678.In one of the backend's python files, place a
breakpoint()somewhere where you want the code execution to break. Start VS Code's debugging by pressingF5on your keyboard and open the part of the MUSCLE application that executes the code where you placed a breakpoint. In my case, I added a breakpoint to thenext_roundmethod insession/views.py(1). The frontend clearly cannot load the next round yet (the code execution is interrupted):My VS Code then allows me to resume code execution (2), step in/out of deeper executions, or allows me to see local and global variables(3):