non blocking socket.accept()

Martin Sjögren martin at strakt.com
Mon Jun 17 09:56:02 EDT 2002


On Mon, Jun 17, 2002 at 01:45:05PM +0000, Zsolt Marx wrote:
> I far as I know socket.accept() waits for a client
> to ask for a connection with the server.
> 
> This command seems to be blocking, though I would
> like to limit the wait time onto a predefined interval
> and to throw an error, if there is no connection.
> 
> How can I achieve this?

You will probably be able to do this with the new timout sockets, but in
the meantime, check out the select module:

import select
if select.select([serversock], [], [], timeout):
    client,addr = serversock.accept()


Regards,
Martin

-- 
Martin Sjögren
  martin at strakt.com              ICQ : 41245059
  Phone: +46 (0)31 7710870       Cell: +46 (0)739 169191
  GPG key: http://www.strakt.com/~martin/gpg.html





More information about the Python-list mailing list