Multiprocessing vs Threading Python [duplicate]

This question already has answers here:

What are the differences between the threading and multiprocessing modules?

(6 answers)

Closed 6 months ago.

I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?


The threading module uses threads, the multiprocessing module uses processes. The difference is that threads run in the same memory space, while processes have separate memory. This makes it a bit harder to share objects between processes with multiprocessing. Since threads use the same memory, precautions have to be taken or two threads will write to the same memory at the same time. This is what the global interpreter lock is for.

Spawning processes is a bit slower than spawning threads.

以上是 Multiprocessing vs Threading Python [duplicate] 的全部内容, 来源链接: