蟒蛇/二郎:有什么扭曲的,无堆栈,Greenlet,Eventlet,协同程序之间的区别?他们是类似于Erlang进程? [英] Python/Erlang: What's the difference between Twisted, Stackless, Greenlet, Eventlet, Coroutines? Are they similar to Erlang processes?

查看:298
本文介绍了蟒蛇/二郎:有什么扭曲的,无堆栈,Greenlet,Eventlet,协同程序之间的区别?他们是类似于Erlang进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不完全理解是扭曲的,无堆栈,Greenlet,Eventlet,协同程序都使用异步网络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进程。他们是pretty同样的事情?

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

任何人谁可以帮助我理解这个话题更是大大AP preciated。

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.

现在


  • 扭曲是一个典型的非阻塞I / O架构 - 应用code被写入使用异步回调风格

  • GEVENT eventlet 使用的greenlet 的协同程序/ greenthreads / greenlets库。有用于运行事件循环(在GEVENT的情况下,一个专用greenlet这是C- codeD libevent的的事件循环)。当任意greenlet开始等待一些I / O操作过程中,它只是给执行事件循环,启动执行另一个greenlet(这是准备做一些I / O)。这就是所谓的合作多任务 - 每个greenlet决定自己何时返回控制到其他greenlets

  • 无堆栈的具有微进程,这是类似greenlets,但也可以用一个preemptive模型调度 - 这意味着调度程序可以在任何时间停止执行任务蕾和再掀微进程的执行(这是OS线程和Erlang进程是如何工作的)。此外,无堆栈不提供任何非阻塞I / O设备的开箱,所以如果你通过STDLIB I / O操作 - 这将阻止整个操作系统线程,因此没有其他的tasklet可以执行,而你等待I / O。人们试图以提供无堆栈的GEVENT库的港口,但我不知道怎么回事。

  • 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.

这篇关于蟒蛇/二郎:有什么扭曲的,无堆栈,Greenlet,Eventlet,协同程序之间的区别?他们是类似于Erlang进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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