What threading module should I use to prevent disk IO from blocking network IO?
Since you're I/O bound, then use the threading
module.
You should almost never need to use thread
, it's a low-level interface; the threading
module is a high-level interface wrapper for thread
.
The multiprocessing
module is different from the threading module, multiprocessing
uses multiple subprocesses to execute a task; multiprocessing
just happens to use the same interface as threading
to reduce learning curve. multiprocessing
is typically used when you have CPU bound calculation, and need to avoid the GIL (Global Interpreter Lock) in a multicore CPU.
A somewhat more esoteric alternative to multi-threading is asynchronous I/O using asyncore
module. Another options includes Stackless Python and Twisted.