Python, multithreading is too slow, multiprocessing

I'm a multiprocessor newbie

I know something about streaming, but I need to increase the speed of this computation, hopefully with multiprocessing:

Example Description: sends a string to a stream, modifies a string test + send the result back for printing. A.

from threading import Thread

class Alter(Thread):
    def __init__(self, word):
        Thread.__init__(self)
        self.word = word
        self.word2 = ''

    def run(self):
        # Alter string + test processing speed
        for i in range(80000):
            self.word2 = self.word2 + self.word

# Send a string to be altered
thread1 = Alter('foo')
thread2 = Alter('bar')
thread1.start()
thread2.start()

#wait for both to finish
while thread1.is_alive() == True: pass
while thread2.is_alive() == True: pass


print(thread1.word2)
print(thread2.word2)

6 , , .
-, . , , , - , , , . (8 ) multiprocessing.cpu_count(), , . - , , . Python 3

+5
1

threading multiprocessing Thread Process. Pyton () - GIL! SO-post python.

multiprocessing . !

AFAIK . . "" . MPI, ​​ pypar. Linux .

+6

All Articles