Reputation: 21
I'm running a computation heavy program in Python that takes about 10 minutes to run on my system. When I look at CPU usage, one of eight cores is hovering at about 70%, a second is at about 20%, and the rest are close to 0%.Is there any way I can force the program into 100% usage of a single core?
edit: I recognize that utilizing all 8 cores isn't a great option, but is there a way to force the one core into 100% usage?
Upvotes: 1
Views: 4999
Reputation: 4461
For multi-core applications you should use the multiprocessing
module instead of threading
. Python has some (well documented) performance issues with threads. Search google for Global Interpreter Lock for more information about Python and thread performance
Upvotes: 1
Reputation: 4539
Python isn't really multithreaded. You can create threads as a convenient way to manage logical processes, but the application itself has a global thread lock. Because of this, you'll only ever be able to utilize a single thread.
You can use a different flavor of python, but that may provide you with other issues. If you're willing to break it out into distinct processes, you may be able to utilize the subprocess module. This creates two distinct python processes, but they can operate independently. Unfortunately, you'll have to code a method by which they communicate.
Upvotes: 0