Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eventlet vs Greenlet vs gevent?

Tags:

I'm trying to create a GUI framework that will have an event-loop. some threads to handle the UI and some for event handling. I've searched a little bit and found these three libraries and I'm wondering which one is better to use? what are the pros and cons?

I could use one of these three library or even create something for myself by using python threads, or concurrent library.

I would appreciate sharing any kind of experience, benchmark and comparison.

like image 250
mehdy Avatar asked Apr 25 '16 07:04

mehdy


People also ask

What is Eventlet gevent?

gevent is a coroutine-based cooperative multitasking python framework that relies on monkey patching to make all code cooperative. Gevent actually draws its lineage from Eve Online which was implemented using Stackless Python which eventually evolved into eventlet which inspired gevent.

What is gevent greenlet?

gevent is a coroutine -based Python networking library that uses greenlet to provide a high-level synchronous API on top of the libev or libuv event loop. Features include: Fast event loop based on libev or libuv. Lightweight execution units based on greenlets.

What is gevent used for?

Gevent is the use of simple, sequential programming in python to achieve scalability provided by asynchronous IO and lightweight multi-threading (as opposed to the callback-style of programming using Twisted's Deferred).

What is a greenlet?

Greenlets are lightweight thread-like structures that are scheduled and managed inside the process. They are references to the part of the stack that is used by the thread. Compared to POSIX threads (pthreads), there is no stack allocated up front and there is only as much stack as is actually used by the greenlet.


1 Answers

  • You definitely don't want greenlet for this purpose, because it's a low level library on top of which you can create light thread libraries (like Eventlet and Gevent).
  • Eventlet, Gevent and more similar libraries provide excellent toolset for IO-bound tasks (waiting for read/write on file, network).
  • Likely, most of your GUI code will wait for other threads (at this point green/light/OS thread is irrelevant) to finish, which is a perfect target for above mentioned libraries.
  • All green thread libraries are mostly the same. Try all and decide which one suits your project best.
  • But also it's possible that you'll need to extract some things into a separate OS thread due to requirements of OS level GUI layer.
  • Considering that and better implementation of thread lock in Python3 you may want to just stick with native threading module if your application doesn't need hundreds or more threads.
like image 90
temoto Avatar answered Sep 17 '22 18:09

temoto