#NEWLINE# def stop( self , join = False , timeout = None ) : #NEWLINE# #INDENT# 'Stop the threads.\n\n        :Parameters:\n            - `join`: join the threads (wait until they exit)\n            - `timeout`: maximum time (in seconds) to wait when `join` is\n              `True`).  No limit when `timeout` is `None`.\n        ' #NEWLINE# logger . debug ( 'Closing the io handlers...' ) #NEWLINE# for handler in self . io_handlers : #NEWLINE# #INDENT# handler . close ( ) #NEWLINE# #UNINDENT# if self . event_thread . is_alive ( ) : #NEWLINE# #INDENT# logger . debug ( 'Sending the QUIT signal' ) #NEWLINE# self . event_queue . put ( QUIT ) #NEWLINE# #UNINDENT# logger . debug ( '  sent' ) #NEWLINE# threads = ( self . io_threads + self . timeout_threads ) #NEWLINE# for thread in threads : #NEWLINE# #INDENT# logger . debug ( 'Stopping thread: {0!r}' . format ( thread ) ) #NEWLINE# thread . stop ( ) #NEWLINE# #UNINDENT# if ( not join ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if self . event_thread : #NEWLINE# #INDENT# threads . append ( self . event_thread ) #NEWLINE# #UNINDENT# if ( timeout is None ) : #NEWLINE# #INDENT# for thread in threads : #NEWLINE# #INDENT# thread . join ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# timeout1 = ( ( timeout * 0.01 ) / len ( threads ) ) #NEWLINE# threads_left = [ ] #NEWLINE# for thread in threads : #NEWLINE# #INDENT# logger . debug ( 'Quick-joining thread {0!r}...' . format ( thread ) ) #NEWLINE# thread . join ( timeout1 ) #NEWLINE# if thread . is_alive ( ) : #NEWLINE# #INDENT# logger . debug ( '  thread still alive' . format ( thread ) ) #NEWLINE# threads_left . append ( thread ) #NEWLINE# #UNINDENT# #UNINDENT# if threads : #NEWLINE# #INDENT# timeout2 = ( ( timeout * 0.99 ) / len ( threads_left ) ) #NEWLINE# for thread in threads_left : #NEWLINE# #INDENT# logger . debug ( 'Joining thread {0!r}...' . format ( thread ) ) #NEWLINE# thread . join ( timeout2 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . io_threads = [ ] #NEWLINE# self . event_thread = None