Canceling/interrupting raw_input
Daniel Cer
Daniel.Cer at gmail.com
Mon Apr 18 02:28:13 EDT 2005
For what it's worth, this looks like a Windows specific problem.
The code below seems to work as expected on a Linux box. That is,
everything terminates, including the "inputLoop", after sys.exit() is
called, without the user needing to press 'enter' one last time.
However, if I try to run the code on Windows XP, it exhibits the exact
same behavior you described.
#!/usr/bin/python
import thread
import time
import sys
def inputLoop():
while 1:
input_string = raw_input("Type something: ")
print "You entered: ", input_string
thread.start_new_thread(inputLoop, () )
time.sleep(15)
sys.exit()
-Dan
J. W. McCall wrote:
> I'm working on a MUD server and I have a thread that gets keyboard input
> so that you can enter commands from the command line while it's in its
> main server loop. Everything works fine except that if a player enters
> the 'shutdown' command, everything shuts down, but the input thread is
> still sitting waiting for enter to be pressed for raw_input. After
> enter is pressed, it exits back to the command prompt as it should.
>
> I'm wondering if there's a way that I can make the thread stop waiting
> for input. Even sys.exit() still leaves it waiting. It's not a big
> deal, but it bugs me.
>
> Any ideas? Should I be using something other than raw_input? I'm on
> Windows2000 and running this from the DOS prompt. I'm using Python 2.4.
More information about the Python-list
mailing list