简体   繁体   English

在多个内核上运行python线程

[英]Run python threads on multiple cores

I know that Python 2.7 does not allow one to run multiple threads on different cores, and you need to use the multiprocessing module in order to achieve some degree of concurrency. 我知道Python 2.7不允许一个人在不同的内核上运行多个线程,并且您需要使用multiprocessing模块才能实现一定程度的并发性。 I was looking at the concurrent.futures module in Python 3.4. 我正在查看Python 3.4中的concurrent.futures模块。 Does using a ThreadPoolExecutor allow you to run different threads on different processes, or is it still bound by GIL constraints? 使用ThreadPoolExecutor是否允许您在不同的进程上运行不同的线程,还是仍然受到GIL约束的约束? If not, is there a way of running threads on different processors using Python 3.4? 如果没有,是否可以使用Python 3.4在不同的处理器上运行线程?

For my use case, using multiple processes is absolutely not feasible. 对于我的用例,使用多个进程绝对是不可行的。

No. ThreadPoolExector is just a class to help with scheduling work on multiple threads. 否。ThreadPoolExector只是一个类,可以帮助安排多个线程上的工作。 All of the normal thread constraints still apply. 所有常规线程约束仍然适用。

To clear up some confusion, threads will run on different processors / cores as the operating system chooses, they just won't run concurrently. 为了消除混乱,线程将根据操作系统的选择在不同的处理器/内核上运行,它们不会同时运行。 The exception is that some C based functions release the GIL temporarily while performing actions not needing the lock. 唯一的例外是某些基于C的函数在执行不需要锁定的操作时会临时释放GIL。

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

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