【发布时间】:2014-04-03 23:08:03
【问题描述】:
我在 Google 上对 Stackless Python 的 tasklet 进行了大量研究。 每个来源都提到它作为一个线程
stackless.com : Microthreads: tasklets wrap functions allowing them to be launched as microthreads.
但是 tasklet 不是并发的。他们逐段执行代码。
这样的代码:
def function(n):
print n
print n
stackless.schedule()
stackless.tasklet(function)(3)
stackless.tasklet(function)(10)
stackless.run()
将打印
3
3
10
10
一个 tasklet 执行一个代码,直到遇到 stackless.schedule() 然后它从开始或从上次暂停的地方执行下一个 tasklet。
每个程序员都知道“无 GOTO”的黄金法则。我的问题是:
这与 GOTO 有何不同?
如果不并行执行,使用 tasklet 有什么好处?
如果它们不是真正的线程,为什么每个消息来源都提到它们作为线程替代品?
【问题讨论】:
标签: python concurrency python-stackless green-threads