Daniel Engel
Daniel Engel

Reputation: 158

Killing an input in Python

Is there a way to simply kill an input() from another thread? For example, if an amount of time has passed, and the user still didn't enter anything in the input(), is there a way to simply "kill" the input()?

Upvotes: 2

Views: 1024

Answers (1)

Reaper
Reaper

Reputation: 757

You can't kill an input(). However, you could do pretty much the same using sys.stdin iterable, for loop and a flag (or some function).

import sys

stopReadingInput = False
for line in sys.stdin :
    # Insert some code that involves user input
    if stopReadingInput : # Here you can call a function to check if you don't need user input anymore, instead of if statement. Otherwise you'll have to change the flag value from outside.
        break

Upvotes: 1

Related Questions