From c2eb7897bc808373c26bf9cb884b2398a8a5e19d Mon Sep 17 00:00:00 2001 From: Sam Colwell Date: Sun, 4 Nov 2018 12:04:59 -0500 Subject: [PATCH] Change non-blocking reads to have 0.1 second timeout --- py65/monitor.py | 4 ++-- py65/utils/console.py | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/py65/monitor.py b/py65/monitor.py index 9560fe8..9e52bae 100644 --- a/py65/monitor.py +++ b/py65/monitor.py @@ -480,9 +480,9 @@ class Monitor(cmd.Cmd): newattr = self.oldattr[:] newattr[3] &= ~termios.ICANON & ~termios.ECHO - # Switch to non-blocking reads. + # Switch to non-blocking reads with 0.1 second timeout. newattr[6][termios.VMIN] = 0 - newattr[6][termios.VTIME] = 0 + newattr[6][termios.VTIME] = 1 termios.tcsetattr(fd, termios.TCSANOW, newattr) diff --git a/py65/utils/console.py b/py65/utils/console.py index 64a51a4..380377f 100644 --- a/py65/utils/console.py +++ b/py65/utils/console.py @@ -35,10 +35,8 @@ else: Does not echo the character. """ # Try to get a character with a non-blocking read. - char = stdin.read(1) + char = '' while char == '': - # If we don't get one right away, wait a bit and try again. - time.sleep(0.001) char = stdin.read(1) return char @@ -49,9 +47,7 @@ else: char = '' # Using non-blocking read as set up in Monitor._run char = stdin.read(1) - if char == '': - # Don't use 100% CPU while waiting for input. - time.sleep(0.001) + if char == "\n": char = "\r" return char