The last fix I checked in to this file was a bit obscure; added a comment in the code to explain what sys.stdin.detach() does and why it is needed.