question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

-h/--help arg to program instead shows help for interpreter

See original GitHub issue

Environment data

  • VS Code version: 1.27.2
  • Extension version (available under the Extensions sidebar): 2018.8.0
  • OS and version: Windows 10 (1709)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.0
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): N/A
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

my-file.py contains:

import argparse
version = '1.0.0'

def main():
    arg_parser = argparse.ArgumentParser(description='Foo')
    try:
        args = arg_parser.parse_args()
    except Exception as e:
        traceback.print_exc()
        exit(1)
    exit(0)

if __name__ == '__main__':
    main()

launch.json contains:

        {
            "name": "Python: Current File - help arg",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "args": [
                "--help"  // or "-h"
            ]
        },

Outputs the help for the python interpreter:

cd <my-workspace-path> && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && set "PYTHONPATH=c:\Users\<username>\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd" && python -m ptvsd --host localhost --port 60918 <my-file-path>.py --help "
usage:
  python.exe -m ptvsd [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT -m MODULE [arg ...]
  python.exe -m ptvsd [-h] [-V] [--nodebug] [--host HOST | --server-host HOST] --port PORT FILENAME [arg ...]

positional arguments:
  filename

optional arguments:
  -h, --help            show this help message and exit
  --nodebug
  --host HOST
  --server-host SERVER_HOST
  --port PORT
  -m MODULE
  --single-session
  -V, --version         show program's version number and exit

Then after some ten seconds or so, shows an error like:

[Window Title] Visual Studio Code

[Content] Timeout waiting for debugger connection

[Open launch.json] [Cancel]

Expected behavior

Evaluate the help arg as an argument to my file, i.e. respond with my file’s response to the -h arg

Steps to reproduce:

  1. create a python script that handles -h and --help args
  2. add a configuration to launch.json to call the script with one of these args
  3. launch using the created configuration
  4. check the output

Logs

No logs created

Other arguments appear to work as intended.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
KubaOcommented, Nov 12, 2018

ptvsd uses Python’s argparse.py: to leave arguments unparsed, precede them with the "--" argument. Thus, the launch.json should be:

    {
        "name": "Python: Current File - help arg",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "args": ["--", "--help"]
    }

Reference: https://stackoverflow.com/a/9084137/1329652

0reactions
brettcannoncommented, Feb 15, 2019

@ruyman-vfx nothing is planned to support passing arguments to ptvsd_launcher.py as there shouldn’t be anything you need there which isn’t provided as an argument in launch.json.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why doesn't python use its own argparse library for its associated ...
The python module has argparse to pass command-line arguments. ... it call the interpreted argparse Python code before starting the Python interpreter?
Read more >
2. Using the Python Interpreter — Python 3.11.1 documentation
A second way of starting the interpreter is python -c command [arg] ... , which executes the statement(s) in command, analogous to the...
Read more >
Interpreter Files
where pathname is the path of the interpreter and arg is a single ... The following example shows how to create and execute...
Read more >
Interpreter Rules of Conduct | Judicial Administration
As officers of the court, interpreters help assure that such persons ... Verbal and non-verbal displays of personal attitudes, prejudices, ...
Read more >
Foundations of Interpretation Curriculum Content Narrative
by a philosophy that charges interpreters to help audiences care about park ... he became concerned about the quality of interpretive programs in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found