再写一个comet-like Web app的时候,无意中翻到了上古神器Eurasia3,也翻到了stackless,每次碰到stackless就小小的震撼一下,就像阳光照不到的阴暗角落,不知道哪里有什么样稀奇古怪的东西。还是在IBM developerWorks上翻到了一点支离破碎的东西(中文 | 英文):
Mertz:Stackless Python 确切来说是什么?有什么初学者可以理解的概念能够解释有关 Stackless 的不同之处?
Tismer:Stackless Python 是一种不在 C 堆栈上保存状态的 Python 实现。它的确有堆栈 -- 要多少有多少 -- 但这些是 Python 堆栈。
C 堆栈不能从例如 C 这样的语言以干净的方式进行修改,除非以预期的顺序进行。它对您施加了很大限制:您必须回到这里,与您离开的方向正好相反。
“普通的”程序员一开始不会认为这是个限制。他们必须从开始就要学会将想法转向堆栈。堆栈没有什么坏处,并且通常它们施加的执行顺序就是实际上的顺序,但这并不意味着我们必须等待一个这样的堆栈序列完成才能运行另一序列。
程序员在必须执行非阻塞调用和回调时意识到这一点。堆栈突然挡住去路,我们必须使用线程,或将状态明确存储在对象中,或者构建显式的可切换堆栈等等。Stackless 的目的是帮助程序员避免这些问题。
Mertz: Exactly what is Stackless Python? Is there something a beginner can get his or her mind around that explains what is different about Stackless?
Tismer: Stackless Python is a Python implementation that does not save state on the C stack. It does have stacks -- as many as you want -- but these are Python stacks.
The C stack cannot be modified in a clean way from a language like C, unless you do it in the expected order. It imposes a big obligation on you: You will come back, exactly here, exactly in the reverse way as you went off.
"Normal" programmers do not see this as a restriction in the first place. They have to learn to push their minds onto stacks from the outset. There is nothing bad about stacks, and usually their imposed execution order is the way to go, but that does not mean that we have to wait for one such stack sequence to complete before we can run a different one.
Programmers realize this when they have to do non-blocking calls and callbacks. Suddenly the stack is in the way, we must use threads, or explicitly store state in objects, or build explicit, switchable stacks, and so on. The aim of Stackless is to deliver the programmer from these problems.
还是一片空白啊。但是感觉HTML - CGI - AJAX这一些东西一路过来,可能对并发编程有相当大的促进吧?加上现在的comet,简直是 ** 性的东西。
顺便看了一下文章发表的时间:
David Mertz (mertz@gnosis.cx), President, Gnosis Software, Inc.
01 Oct 2000
瞬间觉得自己超级渺小。8年前我在做什么?跟老师在昏暗沉闷的微机室学习DOS, WPS……Guido在1989圣诞节无聊写了个python出来。Tismer在1999无聊写了个stackless