Waiting for keypress

merge-requests/21/head
Bob Mottram 2021-03-04 14:36:24 +00:00
parent f936bf646d
commit 9f19313d3c
2 changed files with 22 additions and 7 deletions

View File

@ -8,14 +8,31 @@ __status__ = "Production"
import os
import html
import sys
import time
from select import select
from session import createSession
from speaker import getSpeakerFromServer
from speaker import getSpeakerPitch
from speaker import getSpeakerRate
from speaker import getSpeakerRange
import signal
def _waitForKeypress(timeout: int, debug: bool) -> str:
"""Waits for a keypress with a timeout
Returns the key pressed, or None on timeout
"""
def _nothing(sig, frame): pass
signal.signal(signal.SIGALRM, _nothing)
signal.alarm(timeout)
keyPress = None
try:
keyPress = input()
signal.alarm(0)
except (IOError, EOFError):
if debug:
print('Keypress Timeout')
return None
print('You typed ' + keyPress)
def runSpeakerClient(baseDir: str, proxyType: str, httpPrefix: str,
@ -109,8 +126,5 @@ def runSpeakerClient(baseDir: str, proxyType: str, httpPrefix: str,
prevSay = speakerJson['say']
# wait for a while, or until a key is pressed
rlist, wlist, xlist = select([sys.stdin], [], [], 30)
if rlist:
print('wlist: ' + str(wlist))
print('xlist: ' + str(xlist))
if _waitForKeypress(30, debug):
break

View File

@ -2998,7 +2998,8 @@ def testFunctions():
'createServerEve',
'E2EEremoveDevice',
'setOrganizationScheme',
'fill_headers'
'fill_headers',
'_nothing'
]
excludeImports = [
'link',