简体   繁体   English

如何为 jupyter notebook 分配更多的 CPU 使用率?

[英]How can I assign more CPU usage to a jupyter notebook?

I am using a shared computer with several CPUs, but when I run a notebook it only uses one CPU.我正在使用具有多个 CPU 的共享计算机,但是当我运行笔记本电脑时,它只使用一个 CPU。 Is there any way I can assign the jupyter notebook to use more of the CPUs available?有什么办法可以让 jupyter notebook 使用更多可用的 CPU?

A way to "assign" more CPU power to a task is not associated with Jupyter IDE but rather is a library within python.将更多 CPU 能力“分配”给任务的方法与 Jupyter IDE 无关,而是 python 中的库。 I would recommend using the multiprocessing library.我建议使用多处理库。 Please refer to this link for the official multiprocessing documentation.请参阅此链接以获取官方多处理文档。 A sample code is provided below:下面提供了一个示例代码:

import multiprocessing


def main(number):
    print(number)


if __name__ == '__main__':
    p1 = Process(target=main, args=(1,))
    p2 = Process(target=main, args=(2,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()

You can think of each of these processes as more CPU power being used to perform a task.您可以将这些进程中的每一个视为用于执行任务的更多 CPU 能力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM