Skip to content

Commit 0b7c6f1

Browse files
mikeprosserniMike Prosser
andauthored
followup comments (#72)
Co-authored-by: Mike Prosser <Mike.Prosser@emerson.com>
1 parent e6602ac commit 0b7c6f1

File tree

5 files changed

+47
-9
lines changed

5 files changed

+47
-9
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,3 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175-
176-
# VS Code settings
177-
.vscode/launch.json

.vscode/launch.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Python Debugger: Current File",
9+
"type": "debugpy",
10+
"request": "launch",
11+
"program": "${file}",
12+
"console": "integratedTerminal"
13+
},
14+
{
15+
// To use this configuration, add `debugpy.listen(("localhost", 5678))` to the script you wish to debug
16+
"name": "Attach to Streamlit at localhost:5678",
17+
"type": "debugpy",
18+
"request": "attach",
19+
"connect": {
20+
"host": "localhost",
21+
"port": 5678
22+
},
23+
"justMyCode": false
24+
}
25+
]
26+
}

CONTRIBUTING.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ start docs\_build\index.html
5656

5757
# Debugging on the streamlit side
5858

59-
Debugging the measurement script can be done using standard Python debugging techniques. However, debugging the Streamlit script—or any code invoked by the Streamlit script—is more complex because it runs in a separate process launched by the PythonPanelServer. To debug the Streamlit script, you can use debugpy to attach the Visual Studio Code debugger as follows:
59+
Debugging the measurement script can be done using standard Python debugging
60+
techniques. However, debugging the Streamlit script—or any code invoked by the
61+
Streamlit script—is more complex because it runs in a separate process launched
62+
by the PythonPanelServer. To debug the Streamlit script, you can use debugpy to
63+
attach the Visual Studio Code debugger as follows:
6064

6165
## Instrument Streamlit script to debug
6266

@@ -73,9 +77,15 @@ except RuntimeError as e:
7377
raise
7478
```
7579

76-
The `debugpy.listen()` function opens a port that allows the debugger to attach to the running process. You can specify any available port, as long as it matches the port configured in the launch.json file shown below. Since calling listen() more than once will raise an exception, it is wrapped in a try block to prevent the script from crashing if it is rerun.
80+
The `debugpy.listen()` function opens a port that allows the debugger to attach
81+
to the running process. You can specify any available port, as long as it
82+
matches the port configured in the launch.json file shown below. Since calling
83+
listen() more than once will raise an exception, it is wrapped in a try block to
84+
prevent the script from crashing if it is rerun.
7785

78-
The `debugpy.wait_for_client()` function pauses script execution until the debugger is attached. This is helpful if you need to debug initialization code, but you can omit this line if it is not required.
86+
The `debugpy.wait_for_client()` function pauses script execution until the
87+
debugger is attached. This is helpful if you need to debug initialization code,
88+
but you can omit this line if it is not required.
7989

8090
The `import debugpy` statement includes a type suppression comment to satisfy mypy.
8191

@@ -96,7 +106,12 @@ You will also need this configuration in your launch.json:
96106
}
97107
```
98108

99-
After running your measurement script and allowing the PythonPanelServer to launch Streamlit with your Streamlit script, you can attach the debugger by clicking the **Attach to Streamlit at localhost:5678** button in the VS Code **Run and Debug** tab. Once attached, you can set breakpoints and use all standard debugging features in your Streamlit script, as well as in any nipanel code invoked by the Streamlit script.
109+
After running your measurement script and allowing the PythonPanelServer to
110+
launch Streamlit with your Streamlit script, you can attach the debugger by
111+
clicking the **Attach to Streamlit at localhost:5678** button in the VS Code
112+
**Run and Debug** tab. Once attached, you can set breakpoints and use all
113+
standard debugging features in your Streamlit script, as well as in any nipanel
114+
code invoked by the Streamlit script.
100115

101116
# Developer Certificate of Origin (DCO)
102117

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ni-measurement-plugin-sdk = {version=">=2.3"}
1414
typing-extensions = ">=4.13.2"
1515
streamlit = ">=1.24"
1616
nitypes = {version=">=0.1.0dev1", allow-prereleases=true}
17-
debugpy = "^1.8.1"
17+
debugpy = ">=1.8.1"
1818

1919
[tool.poetry.group.dev.dependencies]
2020
types-grpcio = ">=1.0"

0 commit comments

Comments
 (0)