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

Patch for bugs in pty.py #46741

Closed
fergushenderson mannequin opened this issue Mar 26, 2008 · 12 comments
Closed

Patch for bugs in pty.py #46741

fergushenderson mannequin opened this issue Mar 26, 2008 · 12 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@fergushenderson
Copy link
Mannequin

fergushenderson mannequin commented Mar 26, 2008

BPO 2489
Nosy @gpshead, @pitrou, @devdanzin, @bitdancer
Files
  • pty.py.patch: Patch to Lib/pty.py
  • pty.py.patch2: Patch for (1)+(2): waitpid and return status
  • pty.py.patch3: Patch for (3): _copy loop bug
  • 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/gpshead'
    closed_at = <Date 2012-09-29.19:41:30.345>
    created_at = <Date 2008-03-26.01:15:48.416>
    labels = ['type-bug', 'library']
    title = 'Patch for bugs in pty.py'
    updated_at = <Date 2012-09-29.20:03:48.720>
    user = 'https://bugs.python.org/fergushenderson'

    bugs.python.org fields:

    activity = <Date 2012-09-29.20:03:48.720>
    actor = 'pitrou'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2012-09-29.19:41:30.345>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2008-03-26.01:15:48.416>
    creator = 'fergushenderson'
    dependencies = []
    files = ['9861', '14149', '18666']
    hgrepos = []
    issue_num = 2489
    keywords = ['patch']
    message_count = 12.0
    messages = ['64533', '64534', '64535', '87914', '88683', '115120', '115121', '115123', '153466', '153467', '171593', '171594']
    nosy_count = 8.0
    nosy_names = ['gregory.p.smith', 'pitrou', 'ajaksu2', 'gpolo', 'fergushenderson', 'psss', 'r.david.murray', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue2489'
    versions = ['Python 3.3']

    @fergushenderson
    Copy link
    Mannequin Author

    fergushenderson mannequin commented Mar 26, 2008

    The attached patch fixes some bugs in the pty.py module:

    • spawn() would not wait for the invoked process to finish.
      Also, it did not return a meaningful value, so there was no way
      to tell if the invoked process failed. After this patch,
      spawn() now waits for the invoked process, and returns the value
      returned from os.waitpid().

    • There was a bug in the _copy() loop that caused it to spin
      using 100% CPU rather than blocking after EOF was reached on
      one of the two file descriptors that it was waiting for.

    @fergushenderson fergushenderson mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 26, 2008
    @gpolo
    Copy link
    Mannequin

    gpolo mannequin commented Mar 26, 2008

    Hi Fergus,

    I would suggest using "if not data" to check for EOF

    @fergushenderson
    Copy link
    Mannequin Author

    fergushenderson mannequin commented Mar 26, 2008

    On Tue, Mar 25, 2008 at 9:22 PM, Guilherme Polo <report@bugs.python.org> wrote:

    I would suggest using "if not data" to check for EOF

    Good idea.

    @devdanzin
    Copy link
    Mannequin

    devdanzin mannequin commented May 16, 2009

    Fergus,
    Can you provide a test for the _copy loop bug? IIUC, the spawn change is
    an RFE and shouldn't land on the maintenance branches (or 3.1).

    @fergushenderson
    Copy link
    Mannequin Author

    fergushenderson mannequin commented Jun 1, 2009

    The spawn change (the last hunk of the original patch) is a bug fix, not
    an RFE.
    It has two parts that fix two bugs:
    (1) a coding bug: spawn() would not wait for the invoked process to
    finish. This is fixed by the line that adds the call to os.waitpid().
    (2) a design bug: because previously spawn() didn't return a value,
    there is no way to tell if the invoked process failed. This is fixed by
    the "return status" line.

    Now I guess you can argue that (2) is an RFE.
    But (1) is just a bug fix, not an RFE, IMHO.

    Those are both separate from the other bug fixed in the patch:
    (3) Another coding bug: the bug in the _copy() loop that caused
    it to spin using 100% CPU rather than blocking

    It's a little tricky to write a test of the _copy() loop bug, for
    several reasons.
    (a) There currently isn't any test for pty.spawn, apparently since
    "Cannot do extensive 'do or fail' testing because pty code is not too
    portable."
    (b) Also, for this bug the symptom is just that the code spins (using
    100% CPU, if available) rather than blocking. It's difficult to detect
    that situation using portable code.

    I can maybe figure out how deal with (a), but I'm not sure how to
    address (b), especially since I don't know the intended portability goals.

    I will split the patch up into two patches, one of which addresses
    (1)+(2), and the other of which addresses (3).

    I have addressed Guilherme Polo's suggestion about using "if not data".

    @bitdancer
    Copy link
    Member

    Woops, didn't mean to delete that file. Reattaching.

    @bitdancer
    Copy link
    Member

    That didn't work so well :(

    @bitdancer
    Copy link
    Member

    OK, file restored.

    Design bugs are usually fixed by "feature requests" :)

    See bpo-967171 for the feature request.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Feb 16, 2012

    New changeset 994659efa292 by Gregory P. Smith in branch '3.2':
    Issue bpo-2489: Fix bug in _copy loop that could consume 100% cpu on EOF.
    http://hg.python.org/cpython/rev/994659efa292

    New changeset c7338f62f956 by Gregory P. Smith in branch 'default':
    Issue bpo-2489: Fix bug in _copy loop that could consume 100% cpu on EOF.
    http://hg.python.org/cpython/rev/c7338f62f956

    New changeset f889458c65cc by Gregory P. Smith in branch '2.7':
    Issue bpo-2489: Fix bug in _copy loop that could consume 100% cpu on EOF.
    http://hg.python.org/cpython/rev/f889458c65cc

    @gpshead
    Copy link
    Member

    gpshead commented Feb 16, 2012

    I'm keeping this open to address the added behavior for spawn in 3.3.

    @gpshead gpshead self-assigned this Feb 16, 2012
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Sep 29, 2012

    New changeset ec2921d4de37 by Gregory P. Smith in branch 'default':
    pty.spawn() now returns the child process status as returned by os.waitpid().
    http://hg.python.org/cpython/rev/ec2921d4de37

    @gpshead gpshead closed this as completed Sep 29, 2012
    @pitrou
    Copy link
    Member

    pitrou commented Sep 29, 2012

    The test breaks on OpenIndiana (and possibly elsewhere):
    http://buildbot.python.org/all/builders/x86%20OpenIndiana%203.x/builds/4640

    ======================================================================
    FAIL: test_spawn_returns_status (test.test_pty.PtyTest)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/test/test_pty.py", line 200, in test_spawn_returns_status
        status = pty.spawn([sys.executable, '-c', 'import sys; sys.exit(0)'])
      File "/export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/pty.py", line 175, in spawn
        _copy(master_fd, master_read, stdin_read)
      File "/export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/pty.py", line 147, in _copy
        rfds, wfds, xfds = select(fds, [], [])
      File "/export/home/buildbot/32bits/3.x.cea-indiana-x86/build/Lib/test/test_pty.py", line 65, in handle_sig
        self.fail("isatty hung")
    AssertionError: isatty hung

    @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

    3 participants