Skip to content

Commit

Permalink
Don't try to patch arguments when not dealing with python. Fixes micr…
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Jul 12, 2019
1 parent ada7f93 commit 13ff40a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/ptvsd/multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -136,6 +135,7 @@ def _subprocess_listener():


def _handle_subprocess(n, stream):

class Handlers(object):
_pid = None

Expand Down Expand Up @@ -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 == '-':
Expand Down
44 changes: 42 additions & 2 deletions tests/func/test_multiproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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()

0 comments on commit 13ff40a

Please sign in to comment.