to avoid blocking on calls to ones that are not that iswhen the sources passed to select are socketswe can be sure that socket calls like acceptrecvand send will not block (pausethe server when applied to objects returned by select because of thata single-loop server that uses select need not get stuck communicating with one client or waiting for new ones while other clients are starved for the server' attention because this type of server does not need to start threads or processesit can be efficient when transactions with clients are relatively short-lived howeverit also requires that these transactions be quickif they are notit still runs the risk of becoming bogged down waiting for dialog with particular client to endunless augmented with threads or forks for long-running transactions | select-based echo server let' see how all of this translates into code the script in example - implements another echo serverone that can handle multiple clients without ever starting new processes or threads example - pp \internet\sockets\select-server py ""serverhandle multiple clients in parallel with select use the select module to manually multiplex among set of socketsmain sockets which accept new client connectionsand input sockets connected to accepted clientsselect can take an optional th arg-- to polln to wait secondsor omitted to wait till any socket is ready for processing ""import systime from select import select from socket import socketaf_inetsock_stream def now()return time ctime(time time()myhost 'myport if len(sys argv= myhostmyport sys argv[ :numportsocks server machine'means local host listen on non-reserved port number allow host/port as cmdline args too number of ports for client connects make main sockets for accepting new client requests mainsocksreadsockswritesocks [][][for in range(numportsocks)portsock socket(af_inetsock_streammake tcp/ip socket object |confusinglyselect-based servers are often called asynchronousto describe their multiplexing of short-lived transactions reallythoughthe classic forking and threading servers we met earlier are asynchronoustooas they do not wait for completion of given client' request there is clearer distinction between serial and parallel servers--the former process one transaction at time and the latter do not--and "synchronousand "asynchronousare essentially synonyms for "serialand "parallel by this definitionforkingthreadingand select loops are three alternative ways to implement parallelasynchronous servers handling multiple clients