Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of using the Eventlet module in python over the threading module? [closed]

Specifically the GreenPool class in Eventlet. I have tested some code to upload large files to S3 as individual pieces of a multipart upload. What I have noticed so far is that when using eventlet the CPU usage is much lower. Just looking for other pros and cons for Eventlet over just using threading. Thanks.

like image 223
rking788 Avatar asked Apr 30 '13 22:04

rking788


People also ask

What is Eventlet in Python?

Eventlet is a concurrent networking library for Python that allows you to change how you run your code, not how you write it. It uses epoll or libevent for highly scalable non-blocking I/O.

What is threading and thread module in Python?

The module "thread" treats a thread as a function, while the module "threading" is implemented in an object oriented way, i.e. every thread corresponds to an object.

What is threading event Python?

A threading. Event object wraps a boolean variable that can either be “set” (True) or “not set” (False). Threads sharing the event instance can check if the event is set, set the event, clear the event (make it not set), or wait for the event to be set.

What is the use of threading module in Python?

Practical Data Science using Python The newer threading module included with Python 2.4 provides much more powerful, high-level support for threads than the thread module discussed in the previous section. threading. activeCount() − Returns the number of thread objects that are active.


1 Answers

Basically, Eventlet green threads are to be considered a lightweight analog of OS threads for all practical purposes. Pros:

  • cheaper to create in terms of CPU, memory and syscalls (0)
  • cheaper to switch; this is especially true in Python 2.x where each thread actively tries to grab GIL which wastes CPU.

Cons:

  • important since many green threads operate within one OS thread, when a syscall (e.g. open(2)) in one of them blocks OS thread, all of the green threads are blocked too.
  • no SMP (multicpu/multicore); but then with GIL, this is also true for OS threads in Python. With greenlet[1] this restriction is more strict since it's not possible for some C extension to release GIL to allow other green threads to proceed.

You may also find this answer useful: Is a greenthread equal to a "real" thread

[1] "threading" library used by Eventlet https://github.com/python-greenlet/greenlet

like image 158
temoto Avatar answered Sep 22 '22 20:09

temoto