Use four CPUs to run a python script
I'm running a python scrip开发者_运维问答t that does some operations over a large graph, so I would like to take advantage of the 4 cores of my PC. Watching the task manager I can see that all CPUs are running but the total CPU usage is up to 50%. As I set this PC exclusively to run this script I would like to use its CPUs as much as possible. Is there a python module or anything that can be set in my OS (windows 7) in order to allow me to do that?
C Python has a rather generous lock that precludes most threaded operations from truly happening in parallel. You might want to look at the Multiprocessing module.
Otherwise, you could use a Python implementation that allows for concurrent threading:
- IronPython
- Jython
Have a read through this module:
http://docs.python.org/library/threading.html
for very good work and a more simple example:
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
Hope these help!
精彩评论