#NEWLINE# def server( evt , serv , dataq = None ) : #NEWLINE# #INDENT# ' Open a tcp server in three steps\n        1) set evt to true to let the parent know we are ready\n        2) [optional] if is not False, write the list of data from dataq.get()\n           to the socket.\n    ' #NEWLINE# serv . listen ( 5 ) #NEWLINE# evt . set ( ) #NEWLINE# try : #NEWLINE# #INDENT# ( conn , addr ) = serv . accept ( ) #NEWLINE# if conn : #NEWLINE# #INDENT# data = '' #NEWLINE# new_data = dataq . get ( True , 0.5 ) #NEWLINE# dataq . task_done ( ) #NEWLINE# for item in new_data : #NEWLINE# #INDENT# if ( item == EOF_sigil ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# if ( type ( item ) in [ int , float ] ) : #NEWLINE# #INDENT# time . sleep ( item ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data += item #NEWLINE# #UNINDENT# written = conn . send ( data ) #NEWLINE# data = data [ written : ] #NEWLINE# #UNINDENT# #UNINDENT# conn . close ( ) #NEWLINE# #UNINDENT# except socket . timeout : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# serv . close ( )