Local Debugging With IDE

181 views
Skip to first unread message

nmacneil

unread,
Feb 27, 2021, 6:29:31 PM2/27/21
to py4web
Hi folks,


Can anyone who has gone through this pain already give a concrete step-by-step walkthrough of how to setup py4web debugging of applications on a local machine for vs code/pycharm?

I've been attempting to set it up but have been unable to get it working.

The vs code flask walkthrough seems to have good information but I wasn't able to successfully adapt it to py4web and get it running (https://code.visualstudio.com/docs/python/tutorial-flask).

Details would be much appreciated!


Thanks,
Nathan

Luca de Alfaro

unread,
Feb 27, 2021, 6:40:00 PM2/27/21
to nmacneil, py4web
Here's the run configuration I use in pycharm; you have to modify the paths but it may help you.  After I modify the code, I hit the "rerun" button and that reloads all the code.  Works well enough for me. 

image.png

--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/db550e11-bafc-4bac-b02c-04efbc229523n%40googlegroups.com.

nmacneil

unread,
Feb 27, 2021, 7:51:17 PM2/27/21
to py4web
Thanks Luca. That works to get the server going but I'm really hoping to use breakpoints and step through code as it runs instead of restarting the server with each change and hoping it works. 

I've currently been developing that way for a long time with web2py which has been good as it reloads instantly so a web bases IDE has been great but with py4web I find it quite tedious to track down issues, see what's in context, restart the server, etc. so I'm hoping to set up standard local debugging for the py4web if that's possible.

Luca de Alfaro

unread,
Feb 27, 2021, 9:52:56 PM2/27/21
to nmacneil, py4web
Dear Nathan, 

I haven't been able to set up breakpoints.  I think that the way py4web loads the apps might prevent the code tracking that pycharm requires for breakpoints, but I haven't looked into it.  
However, to me this is not too great an annoyance.  In py4web, I can reload the app just by clicking on the "restart" button of pycharm, and that takes under a second, so I find the debugging quite practical except for the lack of breakpoints. 
The restart button is the top one: 
image.png

Message has been deleted
Message has been deleted

nmacneil

unread,
Feb 27, 2021, 11:52:32 PM2/27/21
to py4web
Hi Luca, 

Thanks for the help, I agree the restart is very quick but I was hoping to be able to step through the code and I seem to have it working now with VS Code.

I'll put my steps for anyone else having issues.
Download git.
Run in terminal, command prompt, etc. : 
Open the folder in VS Code by going to File > Open Folder or via console type code . in the directory you installed py4web.
Click Run > Add Configuration.
Paste and save:
{
          "version": "0.2.0",
          "configurations": [

                     {
                              "name": "py4web",
                              "type": "python",
                              "request": "launch",
                              "program": "${workspaceFolder}\\py4web.py",
                              "args": [
                                         "run",
                                         "apps"
                              ]
                    }
          ]
}

Go to Run > Start Debugging.
Put a breakpoint on one of the lines inside a controller function and it'll hit be it.
Breakpoints for @action.uses( ) and function names seem to only be hit during the initial build of the applications but function contents do hit their breakpoints when navigated to (example below).

Breakpoints one and two are hit during the initial build but only the return line breakpoint is hit when navigating to that route at http://127.0.0.1:8000/examples/index.
Breakpoint.PNG

Hopefully this saves someone else some pain.


- Nathan

Kevin Keller

unread,
Feb 28, 2021, 4:25:29 AM2/28/21
to nmacneil, py4web
There is an email chain about pycharm in this group but not sure it still applies as gevent is not the default wsgi server anymore :

Title of the thread is :

Visual Code debug requirement GEVENT_SUPPORT=True



Reply all
Reply to author
Forward
0 new messages