Am new to python and making some headway with threading
- am doing some music file conversion and want to be able to utilize the multiple cores on my machine (o
If you're using the default "cpython" version then this won't help you, because only one thread can execute at a time; look up Global Interpreter Lock. Instead, I'd suggest looking at the multiprocessing
module in Python 2.6 -- it makes parallel programming a cinch. You can create a Pool
object with 2*num_threads
processes, and give it a bunch of tasks to do. It will execute up to 2*num_threads
tasks at a time, until all are done.
At work I have recently migrated a bunch of Python XML tools (a differ, xpath grepper, and bulk xslt transformer) to use this, and have had very nice results with two processes per processor.