Another socket/thread question
Andrae Muys
amuys at shortech.com.au
Wed Mar 13 19:16:45 EST 2002
Ype Kingma <ykingma at accessforall.nl> wrote in message news:<3C8FA777.8A5B07D1 at accessforall.nl>...
> 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 ()?
>
> When you close the socket from another thread or by the server,
> the pending socket.recv() should terminate with some error condition.
> It's best to test both situations, however.
>
Far cleaner to open a control pipe to the thread and have the thread
wait on both the socket and the pipe. This applies equally to
multi-process and multi-threaded models. This has the added advantage
that you can extend the shutdown protocol to do other things such as
request status, stats, or state-changes.
One hassle with this might be x-platform semantics, as I believe
windows is broken in this regard. Still I would assume windows can
still do pid/interface restricted tcp or preferably unix domain
sockets, which would allow you to emulate the above.
Andrae Muys
More information about the Python-list
mailing list