Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

sys.stdin.read never returns when terminal set to raw mode #1423

Closed
sgorestodd opened this issue May 16, 2019 · 1 comment
Closed

sys.stdin.read never returns when terminal set to raw mode #1423

sgorestodd opened this issue May 16, 2019 · 1 comment
Assignees
Labels

Comments

@sgorestodd
Copy link

sgorestodd commented May 16, 2019

Environment data

  • PTVSD version: 4.2.9
  • OS and version: Kubuntu Linux kernel 5.0
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.3
  • Using VS Code or Visual Studio: VS Code

Actual behavior

sys.stdin.read never returns, even if Enter key is pressed. This is only if the terminal is set to raw mode. Otherwise it works normally.

Expected behavior

sys.stdin.read should return characters that have been entered into stdin while in raw mode. This is a popular method of reading single characters without newlines in Linux as can be seen in these stackoverflow posts.

Python read a single character from the user
Reading a single character (getch style) in Python is not working in Unix

Steps to reproduce:

  1. Toggle character reading via the short program below.
import sys
import termios
import tty

fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
tty.setraw(fd)
# ch = os.read(fd, 1)           # Works
# ch = sys.stdin.buffer.read(1) # Works
ch = sys.stdin.read(1)          # Never returns!
print(ch)
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
  1. Run the program in the integrated terminal with launch.json settings as below.
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal"
    }
  ]
}
@fabioz
Copy link
Contributor

fabioz commented May 20, 2019

I'll investigate.

@fabioz fabioz self-assigned this May 20, 2019
fabioz added a commit to fabioz/ptvsd that referenced this issue May 20, 2019
@fabioz fabioz closed this as completed in 5e93cfd May 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants