1
0
mirror of https://github.com/mnaberez/py65.git synced 2024-06-10 02:29:29 +00:00

Change non-blocking reads to have 0.1 second timeout

This commit is contained in:
Sam Colwell 2018-11-04 12:04:59 -05:00
parent 8a0471e45d
commit c2eb7897bc
2 changed files with 4 additions and 8 deletions

View File

@ -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)

View File

@ -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