Files
deb-python-eventlet/doc/index.rst

2.6 KiB

Eventlet

Eventlet is a networking library written in Python. It achieves high scalability by using non-blocking io while at the same time retaining high programmer usability by using coroutines to make the non-blocking io operations appear blocking at the source code level.

Eventlet is different from all the other event-based frameworks out there because it doesn't require you to restructure your code to use it. You don't have to rewrite your code to use callbacks, and you don't have to replace your main() method with some sort of dispatch method. You can just sprinkle eventlet on top of your normal-looking code.

Web Crawler Example

This is a simple web "crawler" that fetches a bunch of urls using a coroutine pool. It has as much concurrency (i.e. pages being fetched simultaneously) as coroutines in the pool (in our example, 4).

urls = ["http://www.google.com/intl/en_ALL/images/logo.gif",
       "http://wiki.secondlife.com/w/images/secondlife.jpg",
       "http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif"]

import time
from eventlet import coros

# this imports a special version of the urllib2 module that uses non-blocking IO
from eventlet.green import urllib2

def fetch(url):
    print "%s fetching %s" % (time.asctime(), url)
    data = urllib2.urlopen(url)
    print "%s fetched %s" % (time.asctime(), data)

pool = coros.CoroutinePool(max_size=4)
waiters = []
for url in urls:
    waiters.append(pool.execute(fetch, url))

# wait for all the coroutines to come back before exiting the process
for waiter in waiters:
    waiter.wait()

Contents

basic_usage chat_server_example ssl threading testing history

modules

authors

Requirements

Eventlet runs on Python version 2.4 or greater, with the following dependencies:

Areas That Need Work

  • Not enough test coverage -- the goal is 100%, but we are not there yet.
  • Not well-tested on Windows, though it is a supported platform and bug reports are encouraged.
  • The eventlet.processes module is known to not work on Windows.

License

Eventlet is made available under the terms of the open source MIT license

Indices and tables

  • genindex
  • modindex
  • search