简体   繁体   中英

Python stdin readline over 4096 bytes in linux x64?

I have an input line that is longer than 4096 bytes coming into stdin in Python. The code simply says:

while True:
    task_json = sys.stdin.readline()
    task_json = json.loads(task_json.encode('utf-8', 'surrogateescape').decode('utf-8- sig', 'surrogateescape'))

which is truncating line at 4096 bytes. Anyone know a solution? I use python3.6 on ubuntu 16.04 x64. I tried use -u flag - not work. Size of my raw is 9k byte. I can not split this line for \n and modify, i need only stdin from console. May be i can configure console mode, switch to non canon mode?

Canonical mode of TTY needs to be disabled.

def getline(prompt=""):
  fd = sys.stdin.fileno()
  old = termios.tcgetattr(fd)
  new = termios.tcgetattr(fd)
  new[3] = new[3] & ~termios.ICANON
  try:
    termios.tcsetattr(fd, termios.TCSADRAIN, new)
    line = input(prompt)
  finally:
    termios.tcsetattr(fd, termios.TCSADRAIN, old)
  return line

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM