#NEWLINE# def run( self ) : #NEWLINE# #INDENT# "The thread function.\n        \n        First, call the handler's 'prepare' method until it returns\n        `HandlerReady` then loop waiting for the socket input and calling\n        'handle_read' on the handler.\n        " #NEWLINE# interval = self . settings [ 'poll_interval' ] #NEWLINE# prepared = False #NEWLINE# timeout = 0.1 #NEWLINE# while ( not self . _quit ) : #NEWLINE# #INDENT# if ( not prepared ) : #NEWLINE# #INDENT# logger . debug ( '{0}: preparing handler: {1!r}' . format ( self . name , self . io_handler ) ) #NEWLINE# ret = self . io_handler . prepare ( ) #NEWLINE# logger . debug ( '{0}: prepare result: {1!r}' . format ( self . name , ret ) ) #NEWLINE# if isinstance ( ret , HandlerReady ) : #NEWLINE# #INDENT# prepared = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( ret , PrepareAgain ) : #NEWLINE# #INDENT# if ( ret . timeout is not None ) : #NEWLINE# #INDENT# timeout = ret . timeout #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise TypeError ( 'Unexpected result type from prepare()' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if self . io_handler . is_readable ( ) : #NEWLINE# #INDENT# logger . debug ( '{0}: readable' . format ( self . name ) ) #NEWLINE# fileno = self . io_handler . fileno ( ) #NEWLINE# if ( fileno is not None ) : #NEWLINE# #INDENT# readable = wait_for_read ( ret , interval ) #NEWLINE# if readable : #NEWLINE# #INDENT# self . io_handler . handle_read ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not prepared ) : #NEWLINE# #INDENT# if timeout : #NEWLINE# #INDENT# time . sleep ( timeout ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# logger . debug ( '{0}: waiting for readability' . format ( self . name ) ) #NEWLINE# if ( not self . io_handler . wait_for_readability ( ) ) : #NEWLINE# #INDENT# break