#NEWLINE# def dispatch( num , eviction_policy ) : #NEWLINE# #INDENT# with open ( ( 'input-%s.pkl' % num ) , 'rb' ) as reader : #NEWLINE# #INDENT# process_queue = pickle . load ( reader ) #NEWLINE# #UNINDENT# thread_queues = [ Queue . Queue ( ) for _ in range ( THREADS ) ] #NEWLINE# threads = [ threading . Thread ( target = worker , args = ( thread_queue , eviction_policy ) ) for thread_queue in thread_queues ] #NEWLINE# for ( index , triplet ) in enumerate ( process_queue ) : #NEWLINE# #INDENT# thread_queue = thread_queues [ ( index % THREADS ) ] #NEWLINE# thread_queue . put ( triplet ) #NEWLINE# #UNINDENT# for thread_queue in thread_queues : #NEWLINE# #INDENT# thread_queue . put ( None ) #NEWLINE# #UNINDENT# start = time . time ( ) #NEWLINE# for thread in threads : #NEWLINE# #INDENT# thread . start ( ) #NEWLINE# #UNINDENT# for thread in threads : #NEWLINE# #INDENT# thread . join ( ) #NEWLINE# #UNINDENT# stop = time . time ( ) #NEWLINE# timings = { #NEWLINE# #INDENT# 'get' : [ ] , #NEWLINE# 'set' : [ ] , #NEWLINE# 'delete' : [ ] , #NEWLINE# 'self' : ( stop - start ) , #NEWLINE# #UNINDENT# } #NEWLINE# for thread_queue in thread_queues : #NEWLINE# #INDENT# data = thread_queue . get ( ) #NEWLINE# for key in data : #NEWLINE# #INDENT# timings [ key ] . extend ( data [ key ] ) #NEWLINE# #UNINDENT# #UNINDENT# with open ( ( 'output-%s.pkl' % num ) , 'wb' ) as writer : #NEWLINE# #INDENT# pickle . dump ( timings , data , protocol = 2 )