non-blocking sockets

Donn Cave donn at u.washington.edu
Tue Apr 23 12:47:03 EDT 2002


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.

	Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list