GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pty.spawn deadlock · Issue #96522 · python/cpython

pty.spawn deadlock #96522

New issue
Copy link
New issue
Copy link
Closed
Closed
pty.spawn deadlock#96522
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@zhangyoufu
zhangyoufu
opened on Sep 3, 2022
Issue body actions

Bug report

% yes | python3 -c "import pty; pty.spawn(['cat'])"
y
...
y^CTraceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.10/pty.py", line 181, in spawn
    _copy(master_fd, master_read, stdin_read)
  File "/usr/lib/python3.10/pty.py", line 161, in _copy
    _writen(master_fd, data)
  File "/usr/lib/python3.10/pty.py", line 127, in _writen
    n = os.write(fd, data)
KeyboardInterrupt

You will see 2048 lines of y due to tty echo, then the output stops and hangs forever.
Both python and cat block on write, waiting each other consume something from pty buffer.

Your environment

Tested on Linux/macOS with CPython 3.10.

Linked PRs

  • gh-96522: Fix deadlock in pty.spawn #96639
  • [3.11] gh-96522: Fix deadlock in pty.spawn (GH-96639) #104655

Activity

  1. zhangyoufu
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Sep 3, 2022
  2. zhangyoufu commented on Sep 3, 2022

    @zhangyoufu
    zhangyoufu
    on Sep 3, 2022
    ContributorAuthor
    More actions

    pty._copy did not check whether the destination fd is writable.

  3. ambv commented on Oct 5, 2022

    @ambv
    ambv
    on Oct 5, 2022
    Contributor
    More actions

    I can reproduce this with main, and the proposed PR does indeed fix the deadlock.

  4. ambv
    added 3 commits that reference this issue on May 19, 2023

    gh-96522: Fix deadlock in pty.spawn (#96639)

    9c5aa89

    [3.11] pythongh-96522: Fix deadlock in pty.spawn (pythonGH-96639)

    38b5d74

    [3.11] gh-96522: Fix deadlock in pty.spawn (GH-96639) (#104655)

    702ce87
  5. ambv commented on May 19, 2023

    @ambv
    ambv
    on May 19, 2023
    Contributor
    More actions

    Fixed in 3.11 and 3.12.

  6. ambv
    closed this as completedon May 19, 2023
  7. ambv commented on May 19, 2023

    @ambv
    ambv
    on May 19, 2023
    Contributor
    More actions

    Thanks, @zhangyoufu! ✨ 🍰 ✨

    Reacted by Youfu Zhang
  8. carljm
    added a commit that references this issue on May 20, 2023

    Merge branch 'main' into gsallam/main

    ea5965a
  9. teamchong
    added a commit that references this issue on Dec 15, 2025

    fix(ci): Remove flaky test_pty from Linux test group

    8a59a4d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.