Paulo
Paulo

Reputation: 267

Use four CPUs to run a python script

I'm running a python script 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?

Upvotes: 3

Views: 6899

Answers (2)

Nick Bastin
Nick Bastin

Reputation: 31299

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:

Upvotes: 7

Fergus Barker
Fergus Barker

Reputation: 1342

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!

Upvotes: 1

Related Questions