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. 2 7232
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_ne w_thread(inputL oop, () )
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.
Just a little bit of a follow up on this...
If you use win32api.Termin ateProcess() instead of sys.exit(), everything
works as it should on Windows. That is, there is no longer a need to hit
'enter' one last time in order to get "inputLoop" to terminate.
So, modifying the sample code I posted earlier, the new Win32 specific
code would be the following:
import thread
import time
import sys
import win32api
def inputLoop():
while 1:
input_string = raw_input("Type something: ")
print "You entered: ", input_string
thread.start_ne w_thread(inputL oop, () )
time.sleep(3)
print "\nTime's up exiting...."
win32api.Termin ateProcess(-1, 0)
-Dan
Daniel Cer wrote: 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_ne w_thread(inputL oop, () )
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: dale |
last post by:
Python newbie disclaimer on
I am running an app with Tkinter screen in one thread and command-line
input in another thread using raw_input(). First question - is this
legal, should it run without issue? If not can you point me to a
description of why.
While updating objects on the screen I get a segfault after an
indeterminate number of updates. It doesn't seem to matter how quickly
the updates occur, but it does segfault faster...
|
by: JerryKreps |
last post by:
Hi, folks --
I'm a Python pup.
As you can see from the session copied at the end of this post, I have the latest version of Python, and I've been using the Editor-Shell of the latest version of Boa Constructor while going through some Python tutorials.
Everything was working as expected until I started using the raw_input built-in function.
There seems to be some unreliable behavior in Boa Constructor's Editor - Shell. If you look...
|
by: rcarmich |
last post by:
I am having an issue canceling a beginReceive call on a timeout. For
example, the following function:
public int ReadBytes(Socket theSock, byte arr, int
startByte, int length, int timeout)
{
IAsyncResult result = theSock.BeginReceive(arr, startByte,
length, SocketFlags.None, null, null);
if (result.AsyncWaitHandle.WaitOne(timeout, false) ==
|
by: Dox33 |
last post by:
I ran into a very strange behaviour of raw_input().
I hope somebody can tell me how to fix this.
(Or is this a problem in the python source?)
I will explain the problem by using 3 examples. (Sorry, long email)
The first two examples are behaving normal, the thirth is
strange.......
I wrote the following flabbergasting code:
#-------------------------------------------------------------
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |