#NEWLINE# def __init__( self , f , n , wait_before_exit = False ) : #NEWLINE# #INDENT# "\n        Construct a bunch of `n` threads running the same function `f`.\n        If `wait_before_exit` is True, the threads won't terminate until\n        do_finish() is called.\n        " #NEWLINE# self . f = f #NEWLINE# self . n = n #NEWLINE# self . started = [ ] #NEWLINE# self . finished = [ ] #NEWLINE# self . _can_exit = ( not wait_before_exit ) #NEWLINE# def task( ) : #NEWLINE# #INDENT# tid = get_ident ( ) #NEWLINE# self . started . append ( tid ) #NEWLINE# try : #NEWLINE# #INDENT# f ( ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# self . finished . append ( tid ) #NEWLINE# while ( not self . _can_exit ) : #NEWLINE# #INDENT# _wait ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# for i in range ( n ) : #NEWLINE# #INDENT# start_new_thread ( task , ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# self . _can_exit = True #NEWLINE# raise