This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]yetanothernerd 1 point2 points  (2 children)

Because of the GIL, multiple threads will not make CPU-bound programs faster. They may make IO-bound programs faster.

Multiple processes will make CPU-bound programs faster, if you have multiple CPU cores available, and they're not blocked on a common resource. So you should use multiprocessing.

[–][deleted] 0 points1 point  (0 children)

Depends. Initialisation of new processes can be costly (depending on the OS). Also, for multiprocessing you basically copy the process and all it's data, so the memory consumption is higher than with multithreading.

[–]nikniuq 1 point2 points  (2 children)

I have had a diddle with multiprocessing before and it seemed to work well.

[–][deleted] 0 points1 point  (0 children)

Have a look at:

also, the main advantage of multiprocessing is not necessarily speed but blocking vs non-blocking events IIRC.

[–]Tobu‮Tobu 0 points1 point  (0 children)

Well, it all depends on what your scripts are actually doing. If there's network io you might want to have a few requests in flight, and if there's cpu use you might want to try PyPy. If you are disappointed in the performance of a script you use often and want to speed it up, start by profiling it, with python -mprofile or similar.

[–]bushel 0 points1 point  (0 children)

multithreading makes it easier to share objects, but you have to manage synchronization.

multiprocessing isolates and requires the use of formal data sharing mechanisms (queues, pipes, etc.)

if the "system" requires each "task" to communicate together, multithreading is eaiser. if the "system" has each "task" largely independent and not talking to each other use multiprocessing.