-
Notifications
You must be signed in to change notification settings - Fork 9.8k
VSCode Debugging for Frappe Python

Checklist for proper functioning.
- Update
Procfile - Get Visual Studio Code (duh!)
- Install Python Extension for VS Code
- Update
launch.json - Start Debugging
- Disables Auto Reload Feature (However You can achieve the same results by manual reload (⌘⇧F5))
- Disables Werkzeug Multithreading
Caution: This modifies the behaviour of bench start
Comment out a line (prepend # to it) from the Procfile (located in the bench directory) that looks like this.
web: bench serve --port 8000
We will run this process from VS code instead of running it with bench start.
Add a configuration to your launch.json in VS Code that should look something like this (This more or less does exactly what the removed line from Procfile does).
{
"name": "Bench",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/frappe/frappe/utils/bench_helper.py",
"args": [
"frappe", "serve", "--port", "8000", "--noreload", "--nothreading"
],
"pythonPath": "${workspaceFolder}/../env/bin/python",
"cwd": "${workspaceFolder}/../sites",
"env": {
"DEV_SERVER": "1"
}
}
Paths mentioned in given configuration assumes that you have apps directory as your workspace directory (The directory you open code with). workspaceFolder is a vs code variable that points to (if it's not obvious from its name) workspace directory.
You are not forced to use apps as your workspace directory, however do remember to change workspaceFolder, pythonPath and cwd accordingly.
This should be kept running as usual.
VS Code -> Debug Panel (⌘⇧D) -> Start Debugging or With a keyboard shortcut(⌘⇧F5).
"program": "${workspaceFolder}/frappe/frappe/utils/bench_helper.py",
"args": ["frappe", "serve", "--port", "8000", "--noreload", "--nothreading"],
Does exact same thing as bench serve --port 8000 --noreload --nothreading which is same as
cd sites
../env/bin/python ../apps/frappe/frappe/utils/bench_helper.py frappe serve --port 8000 --noreload --nothreading
--noreload diasbles werkezeug's autoreload fetaure and --nothreading disables multithreading.
"cwd": "${workspaceFolder}/../sites",
Above command must be executed from sites directory.
"env": {
"DEV_SERVER": "1"
}
bench start creates an environment variable DEV_SERVER and set it to 1. Socket.io doesn't work correctly without this (long story).
Running only bench serve doesn't set this variable so you need to explicitly set it.
Currently, frappe runs with use_reloader=True and threaded=True, VS Code Debugger for some reason doesn't play well with these features, Django and Flask also have this problem.