使用四个CPU来运行python脚本
我正在运行一个 python 脚本,该脚本对一个大图执行一些操作,因此我想利用我的 PC 的 4 个核心。查看任务管理器,我可以看到所有 CPU 都在运行,但总 CPU 使用率高达 50%。由于我将这台 PC 专门设置为运行此脚本,因此我希望尽可能多地使用它的 CPU。是否有一个 python 模块或任何可以在我的操作系统(Windows 7)中设置的东西,以便我能够做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
C Python 有一个相当慷慨的锁,它阻止大多数线程操作真正并行发生。您可能想查看 Multiprocessing 模块。
否则,您可以使用允许并发线程的 Python 实现:
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:
阅读此模块:
http://docs.python.org/library/threading.html< /a>
非常好的工作和更简单的示例:
http://www.devshed.com/c/a/Python/Basic-Threading-in-Python/
希望这些有所帮助!
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!