Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

passing pathlib.Path object to subprocess.run causes pydevd error only when debugging #601

Closed
MatrixManAtYrService opened this issue Apr 28, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@MatrixManAtYrService
Copy link

Environment data

  • VS Code version: March 2021 (version 1.55)
  • Extension version: v2021.4.765268190
  • OS and version: Mac OS Big Sur 11.3
  • Python version: Python 3.9.4
  • Type of virtual environment used: N/A
  • python.languageServer: jedi

Trouble Code

import subprocess
from pathlib import Path

project_path = Path("./dummyproject")
script = (project_path / 'addone.sh')

subprocess.run([script, "42"])    # causes error only with debugger
subprocess.run([str(script), "42"]).   # works in either case

# addone.sh

#! /usr/bin/env bash
echo "$1 + 1" | bc

Expected behaviour

run without debugging:

❯  cd /Users/matt/src/tdid-proj ; /usr/bin/env /usr/bin/python3 /Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/launcher 57904 -- /Users/matt/src/tdid-proj/dummyproject-test/fingerprints/bug.py ./dummyproject 
43
43

start debugging:

❯  cd /Users/matt/src/tdid-proj ; /usr/bin/env /usr/bin/python3 /Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/launcher 57911 -- /Users/matt/src/tdid-proj/dummyproject-test/fingerprints/bug.py ./dummyproject
43
43

Actual behaviour

run without debugging:

❯  cd /Users/matt/src/tdid-proj ; /usr/bin/env /usr/bin/python3 /Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/launcher 57904 -- /Users/matt/src/tdid-proj/dummyproject-test/fingerprints/bug.py ./dummyproject 
43
43

start debugging:

❯  cd /Users/matt/src/tdid-proj ; /usr/bin/env /usr/bin/python3 /Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/launcher 57883 -- /Users/matt/src/tdid-proj/dummyproject-test/fingerprints/bug.py ./dummyproject 
Error patching args (debugger not attached to subprocess).
Traceback (most recent call last):
  File "/Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 243, in patch_args
    if not is_python(unquoted_args[0]):
  File "/Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 152, in is_python
    single_quote, double_quote = _get_str_type_compatible(path, ["'", '"'])
  File "/Users/matt/.vscode/extensions/ms-python.python-2021.4.765268190/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydev_bundle/pydev_monkey.py", line 136, in _get_str_type_compatible
    ret.append(arg.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'
43
43

Steps to reproduce:

Pass a pathlib.Path object to subprocess.run. Notice that:

  • the debugger fails to attach to the subprocess (fine)
  • errors show up in the output that don't show up without the debugger (not fine)

Workaround

Cast the pathllib.Path object to a string first

Resoning

I never wanted to attach the debugger to the subprocess in the first place. I'm OK with the fact that it failed. But it should faill in a way that doesn't clutter up stdout and make me think my code is broken. Also, more useful errors would be nice.

Thank you.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Apr 28, 2021
@fabioz fabioz self-assigned this Apr 29, 2021
@fabioz fabioz added the bug Something isn't working label Apr 29, 2021
@fabioz fabioz closed this as completed in 11b7124 Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants