ADDED: Handle Prolog signals while waiting for input