#NEWLINE# def test_parallel_threads( ) : #NEWLINE# #INDENT# results = [ ] #NEWLINE# lock = ReentrancyLock ( 'failure' ) #NEWLINE# def worker( k ) : #NEWLINE# #INDENT# with lock : #NEWLINE# #INDENT# time . sleep ( ( 0.01 * ( 3 - k ) ) ) #NEWLINE# results . append ( k ) #NEWLINE# #UNINDENT# #UNINDENT# threads = [ threading . Thread ( target = ( lambda k = k : worker ( k ) ) ) for k in range ( 3 ) ] #NEWLINE# for t in threads : #NEWLINE# #INDENT# t . start ( ) #NEWLINE# #UNINDENT# for t in threads : #NEWLINE# #INDENT# t . join ( ) #NEWLINE# #UNINDENT# assert_equal ( results , sorted ( lock ) )