[英]how to pass one element of an array to a process in multiprocessing
I want to pass each element of an array to a process by multiprocessing in python.我想通过 python 中的多处理将数组的每个元素传递给进程。 How can I do it?
我该怎么做? For example, I have
a[i]
as an array and want to send a[0]
to core 1, a[1]
to core 2,.... Is there any way to do it in python?例如,我将
a[i]
作为数组,并希望将a[0]
发送到核心 1, a[1]
发送到核心 2,.... 在 python 中有什么方法可以做到吗?
CPython (the standard python implementation) has something called the GIL (Global Interpreter Lock),as Gabriel Grant write in this answer Python threads all executing on a single core each time a request to make a new thread is made, the interpreter actually calls into the operating system's libraries and kernel to generate a new thread. CPython(标准 python 实现)有一个叫做 GIL(全局解释器锁)的东西,正如 Gabriel Grant 在这个答案中写的那样Python 线程在每次请求创建一个新线程时都在一个内核上执行,解释器实际上调用操作系统的库和 kernel 生成一个新线程。 so you can use multi-threading to use multitask at the same time but you can't force wich core will be executed
所以你可以使用多线程同时使用多任务,但你不能强制执行哪个核心
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.