#NEWLINE# def start_server( port ) : #NEWLINE# #INDENT# cmd = [ sys . executable , serverscript , '127.0.0.1' , str ( port ) ] #NEWLINE# cmd += sys . argv [ 1 : ] #NEWLINE# p = Popen ( cmd , stdout = PIPE , stderr = PIPE ) #NEWLINE# for i in range ( 30 ) : #NEWLINE# #INDENT# time . sleep ( 0.1 ) #NEWLINE# if ping ( '127.0.0.1' , port ) : #NEWLINE# #INDENT# return ( 'ok' , p ) #NEWLINE# #UNINDENT# rv = p . poll ( ) #NEWLINE# if ( p != None ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# rv = p . poll ( ) #NEWLINE# if ( rv is None ) : #NEWLINE# #INDENT# raise AssertionError ( 'Server took too long to start up.' ) #NEWLINE# #UNINDENT# if ( rv is 3 ) : #NEWLINE# #INDENT# return ( 'port in use' , None ) #NEWLINE# #UNINDENT# raise AssertionError ( ( 'Server exited with error code %d' % rv ) )