PY-24668 Fix debugging of Python subprocesses called with "-c" parameter

This commit is contained in:
Andrey Lisin
2019-04-11 14:18:08 +03:00
parent 39d6b5ab88
commit 407a4b0752
6 changed files with 68 additions and 8 deletions
@@ -45,8 +45,13 @@ def _get_host_port():
def _is_managed_arg(arg):
if arg.endswith('pydevd.py'):
return True
return arg.endswith('pydevd.py')
def _is_already_patched(args):
for arg in args:
if 'pydevd' in arg:
return True
return False
@@ -138,6 +143,9 @@ def patch_args(args):
ind_c = get_c_option_index(args)
if ind_c != -1:
if _is_already_patched(args):
return args
host, port = _get_host_port()
if port is not None:
+8 -6
View File
@@ -1478,15 +1478,19 @@ class DispatchReader(ReaderThread):
self.killReceived = True
DISPATCH_APPROACH_NEW_CONNECTION = 1 # Used by PyDev
DISPATCH_APPROACH_EXISTING_CONNECTION = 2 # Used by PyCharm
DISPATCH_APPROACH = DISPATCH_APPROACH_NEW_CONNECTION
def _should_use_existing_connection(setup):
'''
The new connection dispatch approach is used by PyDev when the `multiprocess` option is set,
the existing connection approach is used by PyCharm when the `multiproc` option is set.
'''
return setup.get('multiproc', False)
def dispatch():
setup = SetupHolder.setup
host = setup['client']
port = setup['port']
if DISPATCH_APPROACH == DISPATCH_APPROACH_EXISTING_CONNECTION:
if _should_use_existing_connection(setup):
dispatcher = Dispatcher()
try:
dispatcher.connect(host, port)
@@ -1616,8 +1620,6 @@ def main():
elif setup['multiproc']: # PyCharm
pydev_log.debug("Started in multiproc mode\n")
global DISPATCH_APPROACH
DISPATCH_APPROACH = DISPATCH_APPROACH_EXISTING_CONNECTION
dispatcher = Dispatcher()
try:
@@ -0,0 +1,5 @@
def boo():
x = 42
print("Hello!")
boo()
@@ -0,0 +1,10 @@
import subprocess
import sys
def foo():
subprocess.call([sys.executable, '-c', "from test_python_subprocess_another_helper import boo"],
stderr=subprocess.PIPE)
return 42
foo()
@@ -0,0 +1,6 @@
from __future__ import print_function
import subprocess
import sys
ret = subprocess.call([sys.executable, '-c', "from test_python_subprocess_helper import foo"], stderr=subprocess.PIPE)
print('The subprocess return code is %d' % ret)
@@ -827,6 +827,35 @@ public class PythonDebuggerTest extends PyEnvTestCase {
});
}
@Test
public void testPythonSubprocessWithCParameter() {
runPythonTest(new PyDebuggerTask("/debug", "test_python_subprocess_with_c_parameter.py") {
@Override
protected void init() {
setMultiprocessDebug(true);
}
@Override
public void before() {
toggleBreakpoint(getFilePath("test_python_subprocess_another_helper.py"), 2);
}
@Override
public void testing() throws Exception {
waitForPause();
eval("x").hasValue("42");
resume();
waitForOutput("Hello!");
}
@NotNull
@Override
public Set<String> getTags() {
return ImmutableSet.of("-iron", "-jython");
}
});
}
@Test
public void testPyQtQThreadInheritor() {
Assume.assumeFalse("Don't run under Windows",UsefulTestCase.IS_UNDER_TEAMCITY && SystemInfo.isWindows);