Another socket/thread question

Cliff Wells logiplexsoftware at earthlink.net
Wed Mar 13 13:43:16 EST 2002


On Wed, 13 Mar 2002 10:37:29 -0800
Ken wrote:

> Hey everyone..
> 
> I've got a thread that continously listens to a socket, and reports what
it
> receives. Blocking is turned on, and I would like it to stay that way
since
> the only thing the thread has to do, is listen to the socket.
> 
> My question is when the socket needs to be closed (program shuts down, or
> that user is being disconnected by the server) is it possible to interupt
a
> socket.recv ()?
> 
> If not, whats the easiest way to cut processor time from looping
endlessly
> with blocking turned off?

You might try using select() with a reasonable timeout period.  Then you
won't busy loop, but you'll be able to check every few seconds to see if
some condition is set that would indicate a program exit.

Alternatively, you could have your shutdown function send something to the
socket itself which would indicate to the thread that it should exit.  Or
even some irrelevant data followed by a test on whether the thread should
exit (the data would never be processed so what it is would be unimportant
- it's used simply to cause socket.recv to return).


-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308




More information about the Python-list mailing list