threads rather than processes threads run in parallel and share global ( module and interpretermemory because threads all run in the same process and memory spacethey automatically share sockets passed between themsimilar in spirit to the way that child processes inherit socket descriptors unlike processesthoughthreads are usually less expensive to startand work on both unix-like machines and windows under standard python today furthermoremany (though not allsee threads as simpler to program--child threads die silently on exitwithout leaving behind zombies to haunt the server to illustrateexample - is another mutation of the echo server that handles client requests in parallel by running them in threads rather than in processes example - pp \internet\sockets\thread-server py ""server sideopen socket on portlisten for message from clientand send an echo replyechoes lines until eof when client closes socketspawns thread to handle each client connectionthreads share global memory space with main threadthis is more portable than forkthreads work on standard windows systemsbut process forks do not""import time_thread as thread from socket import myhost 'myport or use threading thread(start(get socket constructor and constants server machine'means local host listen on non-reserved port number sockobj socket(af_inetsock_streamsockobj bind((myhostmyport)sockobj listen( make tcp socket object bind it to server port number allow up to pending connects def now()return time ctime(time time()current time on the server def handleclient(connection)in spawned threadreply time sleep( simulate blocking activity while truereadwrite client socket data connection recv( if not databreak reply 'echo=>% at % (datanow()connection send(reply encode()connection close(def dispatcher()listen until process killed while truewait for next connectionconnectionaddress sockobj accept(pass to thread for service print('server connected by'addressend='print('at'now()thread start_new_thread(handleclient(connection,)dispatcher( network scripting