本文介绍了无堆栈python和多核?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 所以,我在玩弄 Stackless Python ,并在我脑海中弹出一个问题,也许这是假设或常见的知识,但我找不到它实际上写在无堆栈网站。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. Stackless Python 利用的多核CPU?在正常的Python中,你的GIL是不断存在的,并使(真)使用多个核心你需要使用几个进程,这是真的 Stackless 也?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?推荐答案 Stackless python does 它运行的任何种类的多核环境。 这是一个关于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.内部Stackless使用循环调度器来调度每个 tasklet (微线程),但没有tasklet可以与另一个并发运行。这意味着如果一个tasklet正忙,其他tasklet必须等待,直到该tasklet放弃控制。默认情况下,调度程序不会停止tasklet并给予处理器时间给另一个。使用Stackless.schedule()或者完成其计算,将任务调度到计划队列的末尾是任务的责任。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. Stackless没有多核支持的原因是因为这使线程成为一个整个很容易。这就是无堆叠的一切: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: 从官方无堆栈网站 Stackless Python是一个增强的版本的Python编程语言。它允许程序员获得基于线程的编程的好处,而没有性能和与常规线程相关联的复杂性问题。 Stackless添加到的微线程是一个便宜和轻便的方便,如果正确使用,可以得到以下好处: 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. 这篇关于无堆栈python和多核?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-15 18:12