使用四个CPU来运行python脚本

发布于 2024-11-19 12:19:39 字数 198 浏览 2 评论 0原文

我正在运行一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

·深蓝 2024-11-26 12:19:39

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:

时光暖心i 2024-11-26 12:19:39

阅读此模块:

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文