Python / Erlang:Twisted,Stackless,Greenlet,Eventlet,Coroutines有什么区别?它们是否类似于Erlang进程? [英] Python/Erlang: What's the difference between Twisted, Stackless, Greenlet, Eventlet, Coroutines? Are they similar to Erlang processes?

查看:268
本文介绍了Python / Erlang:Twisted,Stackless,Greenlet,Eventlet,Coroutines有什么区别?它们是否类似于Erlang进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的不完全了解是,Twisted,Stackless,Greenlet,Eventlet,Coroutines都使用异步网络IO和用户线程,这些线程非常轻便,快速地切换。但我不知道他们之间有什么区别。

My incomplete understanding is that Twisted, Stackless, Greenlet, Eventlet, Coroutines all make use of async network IO and userland threads that are very lightweight and quick to switch. But I'm not sure what are the differences between them.

他们听起来与Erlang进程非常相似。他们几乎相同吗?

Also they sound very similar to Erlang processes. Are they pretty much the same thing?

任何可以帮助我更多理解这个话题的人将不胜感激。

Anyone who could help me understand this topic more would be greatly appreciated.

推荐答案

首先,非阻塞I / O与绿线程或协调程序没有任何共同之处,但可以影响它们的安排。

First of all, non-blocking I/O has nothing in common with green threads or coroutines, but it can affect how they're scheduled.

现在:


  • Twisted 是一种经典的非阻塞I / O框架 - 应用代码使用回调以异步风格编写。

  • Gevent eventlet 使用 greenlet 库,用于协程/ greenthreads / greenlets。有一个专用的绿色小路用于运行eventloop(如果是geec它的C编码的 libevent 的事件循环)。当任意的greenlet开始等待一些I / O操作进行处理时,它只会向事件循环执行,该循环将启动另一个执行宏指令(可以做一些I / O)。这就是所谓的合作多任务 - 每个绿叶决定什么时候把控制权返回给其他的小珠。

  • Stackless 具有类似于greenlet的tasklet,但也可以用抢先模式进行调度 - 这意味着调度程序可以随时停止tasklet执行,并开始执行另一个tasklet(这是OS线程和Erlang处理工作)。此外,Stackless不提供任何非阻塞的I / O设备,所以如果您通过stdlib执行I / O,它将阻止整个OS线程,所以在等待我的时候不会执行任何其他的tasklet / O。曾经尝试为Stackless提供一个地理图书馆的港口,但我不知道该怎么做。

  • Twisted is a classic non-blocking I/O framework — application code is written in async style using callbacks.
  • Gevent and eventlet use the greenlet library for coroutines/greenthreads/greenlets. There is one dedicated greenlet for running the eventloop (in case of gevent it's C-coded libevent's event loop). When arbitrary greenlet begins to wait for some I/O operation to process, it just gives execution to the event loop, which starts another greenlet for execution (which is ready to do some I/O). This is called cooperative multitasking — each greenlet decides itself when to return control to other greenlets.
  • Stackless has tasklets, which are similar to greenlets, but can also be scheduled with a preemptive model — that means the scheduler can stop the tasklet execution at any time and start execution of another tasklet (which is how OS threads and Erlang processes work). Also, Stackless does not provide any non-blocking I/O facilities out of the box, so if you do I/O via stdlib — it will block the entire OS thread, so no other tasklet can execute while you're waiting on I/O. There have been attempts to provide a port of the gevent library for Stackless but I don't know how it's going.

这篇关于Python / Erlang:Twisted,Stackless,Greenlet,Eventlet,Coroutines有什么区别?它们是否类似于Erlang进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆