无堆栈Python和多核?
所以,我正在玩 Stackless Python ,一个问题突然出现在我的脑海中,也许这是“假设的” ” 或“常见”知识,但我在 stackless 网站 上找不到实际编写的内容。
Stackless Python 是否利用多核 CPU? 在普通的 Python 中,GIL 始终存在,并且要(真正)使用多个核心,您需要使用多个进程,这对于 Stackless 也可以吗?
So, I'm toying around with Stackless Python and a question popped up in my head, maybe this is "assumed" or "common" knowledge, but I couldn't find it actually written anywhere on the stackless site.
Does Stackless Python take advantage of multicore CPUs? In normal Python you have the GIL being constantly present and to make (true) use of multiple cores you need to use several processes, is this true for Stackless also?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Stackless python不利用其运行的任何类型的多核环境。
这是对 Stackless 的一个常见误解,因为它允许程序员利用基于线程的编程。 对于许多人来说,这两者紧密相连,但实际上是两个独立的事物。
Stackless内部使用循环调度程序来调度每个tasklet(微线程),但没有tasklet可以与另一个同时运行。 这意味着如果一个tasklet 正忙,其他tasklet 必须等待,直到该tasklet 放弃控制权。 默认情况下,调度程序不会停止一个tasklet,并将处理器时间交给另一个tasklet。 Tasklet 负责使用 Stackless.schedule() 将自己调度回调度队列的末尾,或者完成其计算。
因此,即使有多个内核可用,所有微线程也会按顺序执行。
Stackless 不支持多核的原因是这使得线程变得更加容易。 这正是 stackless 的全部内容:
来自官方 stackless 网站
这是链接,指向有关多核和 stackless 的更多信息。
Stackless python does not make use of any kind of multi-core environment it runs on.
This is a common misconception about Stackless, as it allows the programmer to take advantage of thread-based programming. For many people these two are closely intertwined, but are, in fact two separate things.
Internally Stackless uses a round-robin scheduler to schedule every tasklet (micro threads), but no tasklet can be run concurrent with another one. This means that if one tasklet is busy, the others must wait until that tasklet relinquishes control. By default the scheduler will not stop a tasklet and give processor time to another. It is the tasklet's responsibility to schedule itself back in the end of the schedule queue using Stackless.schedule(), or by finishing its calculations.
all tasklets are thus executed in a sequential manner, even when multiplpe cores are available.
The reason why Stackless does not have multi-core support is because this makes threads a whole lot easier. And this is just what stackless is all about:
from the official stackless website
Here is a link to some more information about multiple cores and stackless.