Skip to content

Commit 540d0fc

Browse files
committed
add python debug sample
0 parents  commit 540d0fc

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

.vscode/launch.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Attach (Remote Debug)",
6+
"type": "python",
7+
"request": "attach",
8+
"localRoot": "${workspaceRoot}",
9+
"remoteRoot": "/app",
10+
"port": 3000,
11+
"secret": "my_secret",
12+
"host": "localhost"
13+
}
14+
]
15+
}

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:latest
2+
COPY ./ /app
3+
WORKDIR /app
4+
RUN apt-get update && \
5+
apt-get install -y python-pip && \
6+
pip install -v ptvsd==3.0.0
7+
8+
CMD python hello.py

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Prerequisites
2+
3+
* [Docker](https://www.docker.com/)
4+
* [Visual Studio Code](https://code.visualstudio.com/)
5+
* [Python Extension](https://marketplace.visualstudio.com/items?itemName=donjayamanne.python)
6+
7+
## Build Docker Image
8+
9+
```cmd
10+
docker build -t python-module .
11+
```
12+
13+
## Run Docker Container
14+
15+
```cmd
16+
docker run -d -p 3000:3000 --name python-test python-module
17+
```
18+
19+
## Launch Debugger
20+
21+
Open `PythonModuleDebug` in VS Code. Set up `Breakpoint` and press `F5`.
22+
23+
## Known Bug
24+
25+
The process would add one by one everytime restarting the debugger.

hello.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import os
2+
import sys
3+
import time
4+
import ptvsd
5+
ptvsd.enable_attach("my_secret", address=('0.0.0.0', 3000))
6+
7+
if __name__ == '__main__':
8+
count = 0
9+
while 1:
10+
print('Hello {0}'.format(count))
11+
count += 1
12+
time.sleep(1)

0 commit comments

Comments
 (0)