views:

1497

answers:

3

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?

+1  A: 

saua: Yes, this is was I assumed also - but I can't find any actual proof of this being the case, which is why I'm asking here.

thr
+15  A: 

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 seperate 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 relinquish 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.scedule(), or by finishing it's 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 wat 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.

Sven
A: 

Yes, I was pondering about the same thing as well, but wouldn't it be possible for stackless to analyze tasklets to check for non intrusiveness? eg. tasklet 1 changes var a, tasklet 2 changes var b, as they don't intrude upon each other's space, they can run concurrently without any locking. If they do use resources depending on each other, they can only be run sequentially. Such an implementation would probably not be trivial to implement, but could potentially have great benefits IMHO.

Inscii