What are the modules used to write multi-threaded applications in Python? I'm aware of the basic concurrency mechanisms provided by the language and also of Stackless Python, but what are their respective strengths and weaknesses?
In order of increasing complexity:
Pros:
Cons:
In the simple use case this looks exactly like using threading
except each task is run in its own process not its own thread. (Almost literally: If you take Eli's example, and replace threading
with multiprocessing
, Thread
, with Process
, and Queue
(the module) with multiprocessing.Queue
, it should run just fine.)
Pros:
Cons:
Pros:
Cons:
In all cases I'm assuming you already understand many of the issues involved with multitasking, specifically the tricky issue of how to share data between tasks. If for some reason you don't know when and how to use locks and conditions you have to start with those. Multitasking code is full of subtleties and gotchas, and it's really best to have a good understanding of concepts before you start.