无堆栈Python和多核?

发布于 2024-07-10 17:25:07 字数 442 浏览 7 评论 0原文

所以,我正在玩 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 技术交流群。

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

发布评论

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

评论(1

め可乐爱微笑 2024-07-17 17:25:07

Stackless python利用其运行的任何类型的多核环境。
这是对 Stackless 的一个常见误解,因为它允许程序员利用基于线程的编程。 对于许多人来说,这两者紧密相连,但实际上是两个独立的事物。

Stackless内部使用循环调度程序来调度每个tasklet(微线程),但没有tasklet可以与另一个同时运行。 这意味着如果一个tasklet 正忙,其他tasklet 必须等待,直到该tasklet 放弃控制权。 默认情况下,调度程序不会停止一个tasklet,并将处理器时间交给另一个tasklet。 Tasklet 负责使用 Stackless.schedule() 将自己调度回调度队列的末尾,或者完成其计算。

因此,即使有多个内核可用,所有微线程也会按顺序执行

Stackless 不支持多核的原因是这使得线程变得更加容易。 这正是 stackless 的全部内容:

来自官方 stackless 网站

Stackless Python 是一种增强型
Python 编程版本
语言。 它允许程序员
获得基于线程的好处
没有表演的编程
以及相关的复杂性问题
与传统螺纹。 这
Stackless 添加的微线程
Python 是一种廉价且轻量级的
如果使用的话可以方便
正确的话,可以带来以下好处:

  • 改进了程序结构。
  • 代码更具可读性。
  • 提高程序员的工作效率。

这是链接,指向有关多核和 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

Stackless Python is an enhanced
version of the Python programming
language. It allows programmers to
reap the benefits of thread-based
programming without the performance
and complexity problems associated
with conventional threads. The
microthreads that Stackless adds to
Python are a cheap and lightweight
convenience which can if used
properly, give the following benefits:

  • Improved program structure.
  • More readable code.
  • Increased programmer productivity.

Here is a link to some more information about multiple cores and stackless.

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