A beginner's question on thread

Aurelio Martin amartin at wpsnetwork.com
Tue Apr 6 04:31:31 EDT 2004



Timothy Wu wrote:
> I'm writing a small utility that listens for socket connections, and 
> also repond to user inputs via a text menu selection.
> 
> In order to respond to both the user and the incoming connections I 
> figure I need to use thread.
> 
> I think I would use the main thread to handle the menu and spawn a 
> thread which listens on a socket.
> 
> Now my question is, how do I terminate the server thread if user wants 
> to exit the application? If the server just sit there and listen the 
> thread would never terminate by itself. What kind of inter-thread 
> communications are available and where would I find info/tutorial on that?
> 
> Timothy
> 

Well, when the user wants to exit, the main thread could open a socket 
connection to the server thread, and send a special message telling it 
to stop.

The server thread would have to distinguish between normal connections 
from clients and special connections from the main thread.

Hope this helps

	Aurelio



More information about the Python-list mailing list