You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+19-4Lines changed: 19 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,11 @@ start docs\_build\index.html
56
56
57
57
# Debugging on the streamlit side
58
58
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:
60
64
61
65
## Instrument Streamlit script to debug
62
66
@@ -73,9 +77,15 @@ except RuntimeError as e:
73
77
raise
74
78
```
75
79
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.
77
85
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.
79
89
80
90
The `import debugpy` statement includes a type suppression comment to satisfy mypy.
81
91
@@ -96,7 +106,12 @@ You will also need this configuration in your launch.json:
96
106
}
97
107
```
98
108
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
0 commit comments