Skip to content

Commit c398cd9

Browse files
authored
Add support for pydevd --continue (#74)
1 parent 27b9130 commit c398cd9

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

python/helper-image/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,43 @@
3030
FROM python:2.7 as python27
3131
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
3232
RUN PYTHONUSERBASE=/dbgpy/pydevd/python2.7 pip install --user pydevd --no-warn-script-location
33+
COPY pydevd.patch .
34+
RUN patch -p0 -d /dbgpy/pydevd/python2.7/lib/python2.7/site-packages < pydevd.patch
3335
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python2.7 pip install --user pydevd-pycharm --no-warn-script-location
3436

3537
FROM python:3.5 as python35
3638
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
3739
RUN PYTHONUSERBASE=/dbgpy/pydevd/python3.5 pip install --user pydevd --no-warn-script-location
40+
COPY pydevd.patch .
41+
RUN patch -p0 -d /dbgpy/pydevd/python3.5/lib/python3.5/site-packages < pydevd.patch
3842
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python3.5 pip install --user pydevd-pycharm --no-warn-script-location
3943

4044
FROM python:3.6 as python36
4145
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
4246
RUN PYTHONUSERBASE=/dbgpy/pydevd/python3.6 pip install --user pydevd --no-warn-script-location
47+
COPY pydevd.patch .
48+
RUN patch -p0 -d /dbgpy/pydevd/python3.6/lib/python3.6/site-packages < pydevd.patch
4349
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python3.6 pip install --user pydevd-pycharm --no-warn-script-location
4450

4551
FROM python:3.7 as python37
4652
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
4753
RUN PYTHONUSERBASE=/dbgpy/pydevd/python3.7 pip install --user pydevd --no-warn-script-location
54+
COPY pydevd.patch .
55+
RUN patch -p0 -d /dbgpy/pydevd/python3.7/lib/python3.7/site-packages < pydevd.patch
4856
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python3.7 pip install --user pydevd-pycharm --no-warn-script-location
4957

5058
FROM python:3.8 as python38
5159
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
5260
RUN PYTHONUSERBASE=/dbgpy/pydevd/python3.8 pip install --user pydevd --no-warn-script-location
61+
COPY pydevd.patch .
62+
RUN patch -p0 -d /dbgpy/pydevd/python3.8/lib/python3.8/site-packages < pydevd.patch
5363
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python3.8 pip install --user pydevd-pycharm --no-warn-script-location
5464

5565
FROM python:3.9 as python39
5666
RUN PYTHONUSERBASE=/dbgpy pip install --user ptvsd debugpy
5767
RUN PYTHONUSERBASE=/dbgpy/pydevd/python3.9 pip install --user pydevd --no-warn-script-location
68+
COPY pydevd.patch .
69+
RUN patch -p0 -d /dbgpy/pydevd/python3.9/lib/python3.9/site-packages < pydevd.patch
5870
RUN PYTHONUSERBASE=/dbgpy/pydevd-pycharm/python3.9 pip install --user pydevd-pycharm --no-warn-script-location
5971

6072
FROM golang:1.14.1 as build

python/helper-image/launcher/launcher.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,17 @@ func (pc *pythonContext) updateCommandLine(ctx context.Context) error {
308308
// Appropriate location to resolve pydevd is set in updateEnv
309309
// TODO: check for modules (and fail?)
310310
cmdline = append(cmdline, pc.args[0])
311-
cmdline = append(cmdline, "-m", "pydevd", "--port", strconv.Itoa(int(pc.port)), "--server")
311+
cmdline = append(cmdline, "-m", "pydevd", "--server", "--port", strconv.Itoa(int(pc.port)))
312312
if pc.env["WRAPPER_VERBOSE"] != "" {
313313
cmdline = append(cmdline, "--DEBUG")
314314
}
315315
if pc.debugMode == ModePydevdPycharm {
316316
// From the pydevd source, PyCharm wants multiproc
317317
cmdline = append(cmdline, "--multiproc")
318318
}
319+
if !pc.wait {
320+
cmdline = append(cmdline, "--continue")
321+
}
319322
cmdline = append(cmdline, "--file") // --file is expected as last argument
320323
cmdline = append(cmdline, pc.args[1:]...)
321324
if pc.wait {

python/helper-image/launcher/launcher_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,15 @@ func TestLaunch(t *testing.T) {
275275
description: "pydevd",
276276
pc: pythonContext{debugMode: "pydevd", port: 2345, wait: false, args: []string{"python", "app.py"}, env: nil},
277277
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
278-
AndRunCmd([]string{"python", "-m", "pydevd", "--port", "2345", "--server", "--file", "app.py"}),
279-
expected: pythonContext{debugMode: "pydevd", port: 2345, wait: false, args: []string{"python", "-m", "pydevd", "--port", "2345", "--server", "--file", "app.py"}, env: env{"PYTHONPATH": dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages"}},
278+
AndRunCmd([]string{"python", "-m", "pydevd", "--server", "--port", "2345", "--continue", "--file", "app.py"}),
279+
expected: pythonContext{debugMode: "pydevd", port: 2345, wait: false, args: []string{"python", "-m", "pydevd", "--server", "--port", "2345", "--continue", "--file", "app.py"}, env: env{"PYTHONPATH": dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages"}},
280+
},
281+
{
282+
description: "pydevd with wait",
283+
pc: pythonContext{debugMode: "pydevd", port: 2345, wait: true, args: []string{"python", "app.py"}, env: nil},
284+
commands: RunCmdOut([]string{"python", "-V"}, "Python 3.7.4\n").
285+
AndRunCmd([]string{"python", "-m", "pydevd", "--server", "--port", "2345", "--file", "app.py"}),
286+
expected: pythonContext{debugMode: "pydevd", port: 2345, wait: true, args: []string{"python", "-m", "pydevd", "--server", "--port", "2345", "--file", "app.py"}, env: env{"PYTHONPATH": dbgRoot + "/python/pydevd/python3.7/lib/python3.7/site-packages"}},
280287
},
281288
}
282289

python/helper-image/pydevd.patch

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
diff --git _pydevd_bundle/pydevd_command_line_handling.py _pydevd_bundle/pydevd_command_line_handling.py
2+
index 2afae09..2985a35 100644
3+
--- _pydevd_bundle/pydevd_command_line_handling.py
4+
+++ _pydevd_bundle/pydevd_command_line_handling.py
5+
@@ -69,6 +69,7 @@ ACCEPTED_ARG_HANDLERS = [
6+
ArgHandlerWithParam('client-access-token'),
7+
8+
ArgHandlerBool('server'),
9+
+ ArgHandlerBool('continue'),
10+
ArgHandlerBool('DEBUG_RECORD_SOCKET_READS'),
11+
ArgHandlerBool('multiproc'), # Used by PyCharm (reuses connection: ssh tunneling)
12+
ArgHandlerBool('multiprocess'), # Used by PyDev (creates new connection to ide)
13+
diff --git pydevd.py pydevd.py
14+
index 4639778..9ecfec0 100644
15+
--- pydevd.py
16+
+++ pydevd.py
17+
@@ -1376,6 +1376,8 @@ class PyDB(object):
18+
19+
def run(self):
20+
host = SetupHolder.setup['client']
21+
+ if host is None:
22+
+ host = ''
23+
port = SetupHolder.setup['port']
24+
25+
self._server_socket = create_server_socket(host=host, port=port)
26+
@@ -2240,7 +2242,7 @@ class PyDB(object):
27+
from _pydev_bundle.pydev_monkey import patch_thread_modules
28+
patch_thread_modules()
29+
30+
- def run(self, file, globals=None, locals=None, is_module=False, set_trace=True):
31+
+ def run(self, file, globals=None, locals=None, is_module=False, set_trace=True, wait=True):
32+
module_name = None
33+
entry_point_fn = ''
34+
if is_module:
35+
@@ -2322,7 +2324,8 @@ class PyDB(object):
36+
sys.path.insert(0, os.path.split(os_path_abspath(file))[0])
37+
38+
if set_trace:
39+
- self.wait_for_ready_to_run()
40+
+ if wait:
41+
+ self.wait_for_ready_to_run()
42+
43+
# call prepare_to_run when we already have all information about breakpoints
44+
self.prepare_to_run()
45+
@@ -3276,14 +3279,21 @@ def main():
46+
47+
apply_debugger_options(setup)
48+
49+
+ wait = True
50+
+ if setup['continue']:
51+
+ wait = False
52+
+
53+
try:
54+
- debugger.connect(host, port)
55+
+ if wait:
56+
+ debugger.connect(host, port)
57+
+ else:
58+
+ debugger.create_wait_for_connection_thread()
59+
except:
60+
sys.stderr.write("Could not connect to %s: %s\n" % (host, port))
61+
pydev_log.exception()
62+
sys.exit(1)
63+
64+
- globals = debugger.run(setup['file'], None, None, is_module)
65+
+ globals = debugger.run(setup['file'], None, None, is_module, wait=wait)
66+
67+
if setup['cmd-line']:
68+
debugger.wait_for_commands(globals)

0 commit comments

Comments
 (0)