(seconds: float)
Wait for a keypress or until the given number of seconds have passed,
    whichever happens first.
Wait for a keypress or until the given number of seconds have passed,
    whichever happens first.
Wait for a keypress or until the given number of seconds have passed whichever happens first .
def wait_for_keypress(seconds: float) -> None:
    """Wait for a keypress or until the given number of seconds have passed,
    whichever happens first.
    """
    while seconds > 0:
        if seconds > 1:
            plural = "s"
        else:
            plural = ""

        sys.stdout.write(
            "\rContinuing in %2d second%s; press Enter to continue "
            "immediately. " % (seconds, plural)
        )
        sys.stdout.flush()

        if platform.system() == "Windows":
            from msvcrt import kbhit  # type: ignore

            for _ in range(10):
                if kbhit():
                    seconds = 0
                    break
                sleep(0.1)
        else:
            rlist, _, _ = select([sys.stdin], [], [], 1)
            if rlist:
                sys.stdin.readline()
                seconds = 0
                break

        seconds -= 1

    sys.stdout.write("\r" + " " * 65 + "\r")
def wait_for_keypress ( seconds : float ) -> None : while seconds > 0 : if seconds > 1 : plural = "s" else : plural = "" sys . stdout . write ( "\rContinuing in %2d second%s; press Enter to continue " "immediately. " % ( seconds , plural ) ) sys . stdout . flush ( ) if platform . system ( ) == "Windows" : from msvcrt import kbhit # type: ignore for _ in range ( 10 ) : if kbhit ( ) : seconds = 0 break sleep ( 0.1 ) else : rlist , _ , _ = select ( [ sys . stdin ] , [ ] , [ ] , 1 ) if rlist : sys . stdin . readline ( ) seconds = 0 break seconds -= 1 sys . stdout . write ( "\r" + " " * 65 + "\r" )