Skip to content

Instantly share code, notes, and snippets.

@kylrth
Created August 13, 2019 16:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kylrth/148f061c1f4126dca2bd73cb9ad33007 to your computer and use it in GitHub Desktop.
Save kylrth/148f061c1f4126dca2bd73cb9ad33007 to your computer and use it in GitHub Desktop.
Debugging Bokeh server applications using Visual Studio Code
import ptvsd
# attach to VS Code debugger if this script was run with BOKEH_VS_DEBUG=true
if os.environ['BOKEH_VS_DEBUG'] == 'true':
# 5678 is the default attach port in the VS Code debug configurations
print('Waiting for debugger attach')
ptvsd.enable_attach(address=('localhost', 5678), redirect_output=True)
ptvsd.wait_for_attach()
def main():
"""Create the root and add it to `curdoc()`."""
raise NotImplementedError()
if __name__.startswith('bk_script'):
main()
{
"version": "0.2.0",
"configurations": [
{
"name": "Bokeh server",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"preLaunchTask": "launch Bokeh server"
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "launch Bokeh server",
"type": "shell",
"isBackground": true,
"command": "bokeh",
"args": [
"serve",
"app.py"
],
"options": {
"env": {
"BOKEH_VS_DEBUG": "true"
}
},
"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"endsPattern": "^.*Waiting for debugger attach.*",
"beginsPattern": "^this should not match on anything"
// "^.*\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} 200 GET.*"
}
}
}
]
}
@kylrth
Copy link
Author

kylrth commented Aug 13, 2019

To use this, start debugging, then navigate to the Bokeh app in your browser.

@jsgaston
Copy link

hi, I would need some help understanding this.
1st) it gives an error on BOKEH_VS_DEBUG ... whats this?

@kylrth
Copy link
Author

kylrth commented Jun 28, 2022

That line is reading an environment variable from the shell. You can see it set on line 15 of tasks.json5. Be sure to copy that file into your VS Code debugging configuration.

@jsgaston
Copy link

I'm traying to do this with visual studio. is it the same or similar( vstudio debugging config)?

@jsgaston
Copy link

jsgaston commented Jun 28, 2022

where do I save tasks.json?

@kylrth
Copy link
Author

kylrth commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment