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

Hitting EOF gets cmd.py into a infinite EOF on return loop #57709

Closed
ngie-eign mannequin opened this issue Nov 29, 2011 · 13 comments
Closed

Hitting EOF gets cmd.py into a infinite EOF on return loop #57709

ngie-eign mannequin opened this issue Nov 29, 2011 · 13 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ngie-eign
Copy link
Mannequin

ngie-eign mannequin commented Nov 29, 2011

BPO 13500
Nosy @jcea, @vstinner, @merwok, @ngie-eign
Files
  • python-cmd-reset-lastcmd-on-EOF.patch
  • python-issue13500-test.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/jcea'
    closed_at = <Date 2011-12-06.19:47:47.558>
    created_at = <Date 2011-11-29.14:56:40.420>
    labels = ['type-bug', 'library']
    title = 'Hitting EOF gets cmd.py into a infinite EOF on return loop'
    updated_at = <Date 2012-02-19.03:21:28.289>
    user = 'https://github.com/ngie-eign'

    bugs.python.org fields:

    activity = <Date 2012-02-19.03:21:28.289>
    actor = 'python-dev'
    assignee = 'jcea'
    closed = True
    closed_date = <Date 2011-12-06.19:47:47.558>
    closer = 'python-dev'
    components = ['Library (Lib)']
    creation = <Date 2011-11-29.14:56:40.420>
    creator = 'ngie'
    dependencies = []
    files = ['23805', '24257']
    hgrepos = []
    issue_num = 13500
    keywords = ['patch']
    message_count = 13.0
    messages = ['148575', '148597', '148600', '148932', '148933', '148971', '148972', '148973', '148976', '151431', '153666', '153667', '153668']
    nosy_count = 5.0
    nosy_names = ['jcea', 'vstinner', 'eric.araujo', 'ngie', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue13500'
    versions = ['Python 2.7', 'Python 3.2', 'Python 3.3']

    @ngie-eign
    Copy link
    Mannequin Author

    ngie-eign mannequin commented Nov 29, 2011

    Pressing <enter> produces no output with cmd.py whenever ^D has been entered in; after I enter in ^D it gets into an infinite loop spewing out messages via cmd.Cmd.default() about EOF because self.lastcmd isn't being reset properly.

    The attached patch fixes that usability nit to be more intuitive (I debated about changing 'EOF' to 0x10, but that's probably less intuitive..).

    @ngie-eign ngie-eign mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 29, 2011
    @jcea
    Copy link
    Member

    jcea commented Nov 29, 2011

    Could you provide an step-by-step procedure to try this?.

    @ngie-eign
    Copy link
    Mannequin Author

    ngie-eign mannequin commented Nov 29, 2011

    Sure -- the repro steps are pretty easy:

    1. Startup an interactive python shell.
    2. Enter in the following code:

    {{{
    import cmd
    class Foo(cmd.Cmd):
    def do_bar(self, arg):
    """bar"""

    Foo().cmdloop()
    }}}

    1. You will be greeted with the standard `(Cmd)' prompt.
    2. Press enter. Nothing will be printed out (it will continue on to the next line).
    3. Enter in Control-D, you will be greeted with `Unknown syntax: EOF' error message from cmd.Cmd.default(..).
    4. Press enter multiple times.

    Expected output:

    • Since a do_EOF handler isn't installed in 5., I expect to see the `Unknown syntax: EOF' error print out on the console. I don't want to delve into whether or not this should or shouldn't be printed out in this ticket.
    • Every time I press I should be greeted with the prompt, and not the Unknown syntax: EOF error.

    Actual output:

    • I see `Unknown syntax: EOF' error, and every time I press <enter> it displays the error beforementioned error.

    Example:

    {{{
    >>> import cmd
    >>> class Foo(cmd.Cmd):
    ...     def do_bar(self, arg):
    ...         """bar"""
    ... 
    >>> Foo().cmdloop()
    (Cmd) 
    (Cmd) 
    bar   help  
    (Cmd) help bar
    bar
    (Cmd) ^D*** Unknown syntax: EOF
    (Cmd) 
    *** Unknown syntax: EOF
    (Cmd) 
    *** Unknown syntax: EOF
    }}}

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 6, 2011

    New changeset 5910c385fab6 by Jesus Cea in branch '2.7':
    Close bpo-13500: Hitting EOF gets cmd.py into a infinite EOF on return loop
    http://hg.python.org/cpython/rev/5910c385fab6

    New changeset b6b4d74b8d42 by Jesus Cea in branch '3.2':
    Close bpo-13500: Hitting EOF gets cmd.py into a infinite EOF on return loop
    http://hg.python.org/cpython/rev/b6b4d74b8d42

    New changeset 70ba352f9586 by Jesus Cea in branch 'default':
    MERGE: Close bpo-13500: Hitting EOF gets cmd.py into a infinite EOF on return loop
    http://hg.python.org/cpython/rev/70ba352f9586

    @python-dev python-dev mannequin closed this as completed Dec 6, 2011
    @jcea jcea self-assigned this Dec 6, 2011
    @jcea
    Copy link
    Member

    jcea commented Dec 6, 2011

    Garrett, please verify the fix.

    @merwok
    Copy link
    Member

    merwok commented Dec 7, 2011

    I believe the commit would have needed a regression test.

    @ngie-eign
    Copy link
    Mannequin Author

    ngie-eign mannequin commented Dec 7, 2011

    I'll verify the fix in another day or two.

    FWIW unless python is willing to import pexpect, or provide an equivalent, I'm not sure how items like this which require interactive input can be run via the python project testing framework.

    @merwok
    Copy link
    Member

    merwok commented Dec 7, 2011

    I'm not sure how items like this which require interactive input can
    be run via the python project testing framework.

    Replace sys.stdin with a custom object (a stub) and you can control input (see the Inputs class used in Lib/packaging/tests/test_create.py or Lib/packaging/tests/test_command_register.py). The readline module would not be used however, so that can’t be tested.

    @ngie-eign
    Copy link
    Mannequin Author

    ngie-eign mannequin commented Dec 7, 2011

    Ok. I'll see if I can provide a unittest for this by the 12th.

    @ngie-eign
    Copy link
    Mannequin Author

    ngie-eign mannequin commented Jan 17, 2012

    Here's a unittest patch for the py3k branch.

    {{{
    1 items passed all tests:
    32 tests in test.test_cmd.samplecmdclass
    32 tests in 19 items.
    32 passed and 0 failed.
    Test passed.
    doctest (test.test_cmd) ... 32 tests with zero failures
    test_file_with_missing_final_nl (main.TestAlternateInput) ... ok
    test_input_reset_at_EOF (main.TestAlternateInput) ... ok

    ----------------------------------------------------------------------
    Ran 2 tests in 0.000s

    OK
    }}}

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 19, 2012

    New changeset 5af5e6b2c053 by Jesus Cea in branch 'default':
    Test for issue bpo-13500
    http://hg.python.org/cpython/rev/5af5e6b2c053

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 19, 2012

    New changeset 0d442e166c8f by Jesus Cea in branch '2.7':
    Test for issue bpo-13500
    http://hg.python.org/cpython/rev/0d442e166c8f

    New changeset 3a40af30449e by Jesus Cea in branch '3.2':
    Test for issue bpo-13500
    http://hg.python.org/cpython/rev/3a40af30449e

    New changeset ad204ed6ac51 by Jesus Cea in branch 'default':
    MERGE: Test for issue bpo-13500
    http://hg.python.org/cpython/rev/ad204ed6ac51

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 19, 2012

    New changeset 2909e60e7e13 by Jesus Cea in branch '2.7':
    Fix Test for issue bpo-13500
    http://hg.python.org/cpython/rev/2909e60e7e13

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants