示例#1
0
    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'''
示例#2
0
		def wrapped( *args, **kwargs ):
			thread = Enhanced( notifier.Callback( func, *args, **kwargs ), finished_func )
			thread.run()
示例#3
0
文件: pi.py 项目: c1c51/Python
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)
示例#4
0
def run_async_calculate_center(thread):
    thread.run()