non-blocking sockets
Michael Gilfix
mgilfix at eecs.tufts.edu
Tue Apr 23 15:06:07 EDT 2002
On Tue, Apr 23 @ 16:47, Donn Cave wrote:
> Quoth Michael Gilfix <mgilfix at eecs.tufts.edu>:
> | You need to use the select module to poll the socket. The select
> | module allows you to specify how long you want your timeout (in this
> | case, you probably want a timeout of 0, which is simply a poll) and
> | the module tells you which sockets are waiting for reading/writing.
> |
> | import select
> | read_sock = <my readable socket>
> | w_ready, r_ready, e_ready = select.select ([ ], [ read_sock ], [ ], 0)
> |
> | if read_sock in r_ready:
> | # Process socket
> |
> | ... will probably do what you want.
>
> Yes - and then, we might add, you don't need to make the
> socket non-blocking.
Not necessarily. Depends on his application and how much trust he
places in his network operations..
-- Mike
--
Michael Gilfix
mgilfix at eecs.tufts.edu
For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html
More information about the Python-list
mailing list