def setThreads(self, file): ''' Funcio que calcula els parametres per la funcio map i crea N threads que executraran el map(). En aquesta funcio els parametres depenen del tamany en bytes del tros que volem que un thread analitzi. Es el parametre self.size ''' num_threads = self.getThreads(file) total_size = os.path.getsize(file) size_thread = total_size / num_threads if 'i' in self.arguments: self.printInformation(file) pos_start_read = 0 size_to_read = 0 for iteration in range(num_threads): if iteration + 1 == num_threads: #last thread reads left data size_to_read = total_size - pos_start_read else: size_to_read = self.checkSize(file, size_thread, pos_start_read) thread = threading.Thread(target=self.map, args=(file, size_to_read, pos_start_read)) thread.run() size_to_read += pos_start_read pos_start_read = size_to_read self.reduce(file) os._exit(0) #acaba el proces ''' MAP REDUCE'''
def wrapped( *args, **kwargs ): thread = Enhanced( notifier.Callback( func, *args, **kwargs ), finished_func ) thread.run()
import thread hi = 1 def prin(): if hi == "y": print(no) a = 1 no = 1 / a p = prin() print(a) while True: hi = input() a = a + 2 no = no - 1 / a a = a + 2 no = no + 1 / a thread.run(p)
def run_async_calculate_center(thread): thread.run()