I would like be able to reroute the stdin of my program to a StringIO() object so that I can simulate user response to an input statement.
newstdin = StringIO()
sys.stdin = newstdin
newstdin.write("hey")
newstdin.seek(0)
response = input()
print(response)
My code works when a response is already in the StringIO() object however if there isn't anything, it immediately raises a EOF error instead of waiting for a response like it would if set to the normal sys.stdin. How can I do this so that the input() statement waits for a response to be written to the StringIO() object (this will be done in a separate thread). Thanks!