diff --git a/src/ptvsd/multiproc.py b/src/ptvsd/multiproc.py index 30859ba88..1d8b0f20b 100644 --- a/src/ptvsd/multiproc.py +++ b/src/ptvsd/multiproc.py @@ -28,7 +28,6 @@ from _pydev_bundle import pydev_monkey from _pydevd_bundle.pydevd_comm import get_global_debugger - subprocess_lock = threading.Lock() subprocess_listener_socket = None @@ -136,6 +135,7 @@ def _subprocess_listener(): def _handle_subprocess(n, stream): + class Handlers(object): _pid = None @@ -250,6 +250,8 @@ def patch_args(args): for i, arg in enumerate(args): # Skip Python binary. if i == 0: + if not pydev_monkey.is_python(arg): + return args # We're not dealing with Python, so, don't do anything. continue if arg == '-': diff --git a/tests/func/test_multiproc.py b/tests/func/test_multiproc.py index 4017c15f4..cc04ee9b5 100644 --- a/tests/func/test_multiproc.py +++ b/tests/func/test_multiproc.py @@ -8,7 +8,7 @@ import pytest import sys -from tests.helpers.pattern import ANY +from tests.helpers.pattern import ANY, Regex from tests.helpers.session import DebugSession from tests.helpers.timeline import Event, Request, Response @@ -18,6 +18,7 @@ reason='Debugging multiprocessing module only works on Windows') @pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline']) def test_multiprocessing(pyfile, run_as, start_method): + @pyfile def code_to_debug(): import multiprocessing @@ -127,6 +128,7 @@ def child(q): reason='Bug #935') @pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline']) def test_subprocess(pyfile, run_as, start_method): + @pyfile def child(): import sys @@ -186,6 +188,7 @@ def parent(): reason='Bug #935') @pytest.mark.parametrize('start_method', ['launch', 'attach_socket_cmdline']) def test_autokill(pyfile, run_as, start_method): + @pyfile def child(): from dbgimporter import import_and_enable_debugger @@ -231,10 +234,11 @@ def parent(): @pytest.mark.skipif(sys.version_info < (3, 0) and (platform.system() != 'Windows'), reason='Bug #935') def test_argv_quoting(pyfile, run_as, start_method): + @pyfile def args(): # import_and_enable_debugger - args = [ # noqa + args = [ # noqa r'regular', r'', r'with spaces' @@ -286,3 +290,39 @@ def child(): assert expected_args == actual_args session.wait_for_exit() + + +def test_echo_and_shell(pyfile, run_as, start_method): + ''' + Checks https://github.com/microsoft/ptvsd/issues/1548 + ''' + + @pyfile + def code_to_run(): + from dbgimporter import import_and_enable_debugger + import_and_enable_debugger() + + import sys + import subprocess + + p = subprocess.Popen( + ['echo', 'CheckOK'], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE) + stdout, _stderr = p.communicate() + if sys.version_info[0] >= 3: + stdout = stdout.decode('utf-8') + sys.stdout.write(stdout) + sys.stdout.write('\n') + + with DebugSession() as session: + session.multiprocess = True + session.initialize( + target=(run_as, code_to_run), + start_method=start_method, + ) + + session.start_debugging() + session.wait_for_next( + Event('output', ANY.dict_with({'category': 'stdout', 'output': Regex('CheckOK\\s*')})) + ) + + session.wait_for_exit()