{"id":1475,"library":"eventlet","title":"Eventlet","description":"Eventlet is a concurrent networking library for Python that uses coroutines (greenlets) and non-blocking I/O (epoll/libevent) to enable blocking-style programming in a highly scalable, asynchronous environment. As of version 0.41.0, Eventlet is in maintenance mode, discouraging new projects from using it and planning for its eventual retirement in favor of `asyncio` due to compatibility issues with newer Python versions and a growing gap in maintenance.","status":"deprecated","version":"0.41.0","language":"en","source_language":"en","source_url":"https://github.com/eventlet/eventlet","tags":["concurrency","networking","greenlets","async-io","monkey-patching"],"install":[{"cmd":"pip install eventlet","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Calling `monkey_patch()` early in your application's lifecycle, before other imports, is crucial to ensure all standard library blocking calls are patched correctly.","symbol":"monkey_patch","correct":"import eventlet\neventlet.monkey_patch()"},{"note":"Use `eventlet.spawn` to create greenlets for concurrent execution, not standard Python threads, which are not cooperative.","wrong":"import threading\nthreading.Thread(target=my_function).start()","symbol":"spawn","correct":"import eventlet\neventlet.spawn(my_function, arg1, arg2)"},{"note":"`eventlet.sleep()` cooperatively yields control to the Eventlet hub, allowing other greenlets to run. `time.sleep()` blocks the entire process (after monkey-patching it's patched to be non-blocking but `eventlet.sleep` is the idiomatic way).","wrong":"import time\ntime.sleep(0)","symbol":"sleep","correct":"import eventlet\neventlet.sleep(0)"}],"quickstart":{"code":"import eventlet\nfrom eventlet.green import urllib.request\nimport time\n\neventlet.monkey_patch()\n\ndef fetch_url(url):\n    print(f\"Fetching {url}...\")\n    try:\n        # urllib.request becomes non-blocking after monkey_patch()\n        response = urllib.request.urlopen(url)\n        data = response.read()\n        print(f\"Finished fetching {url}, size: {len(data)} bytes\")\n    except Exception as e:\n        print(f\"Error fetching {url}: {e}\")\n\nif __name__ == '__main__':\n    urls = [\n        'http://www.google.com',\n        'http://www.bing.com',\n        'http://www.yahoo.com',\n    ]\n\n    print(\"Starting concurrent fetches...\")\n    pool = eventlet.GreenPool()\n    for url in urls:\n        pool.spawn(fetch_url, url)\n    pool.waitall()\n    print(\"All fetches complete.\")\n\n    print(\"\\nDemonstrating concurrent sleep:\")\n    def greet(name, delay):\n        eventlet.sleep(delay) # Cooperative sleep\n        print(f\"Hello, {name} after {delay} seconds!\")\n\n    pool_sleep = eventlet.GreenPool()\n    pool_sleep.spawn(greet, \"Alice\", 2)\n    pool_sleep.spawn(greet, \"Bob\", 1)\n    pool_sleep.waitall()\n    print(\"All greetings complete.\")","lang":"python","description":"This quickstart demonstrates Eventlet's core functionality: monkey-patching the standard library for non-blocking I/O and spawning greenlets for concurrent execution. It fetches multiple URLs concurrently and then shows cooperative sleeping."},"warnings":[{"fix":"For new projects, consider using Python's built-in `asyncio` library. For existing Eventlet projects, explore migration paths (e.g., using `EVENTLET_HUB=asyncio`) as provided by Eventlet documentation.","message":"Eventlet is officially in maintenance mode, and new usages are heavily discouraged. The project aims to plan its retirement due to compatibility challenges with modern Python and a shift towards `asyncio` as the preferred concurrency model.","severity":"deprecated","affected_versions":"0.41.0+"},{"fix":"Pin your project to a compatible Python version (e.g., Python 3.11 or older) or prioritize migrating away from Eventlet to `asyncio` to leverage newer Python versions.","message":"Eventlet's monkey-patching mechanism struggles with recent Python versions (e.g., Python 3.12 and beyond), leading to internal functionalities not working correctly or causing unexpected behavior. This limits projects from adopting the latest Python improvements.","severity":"breaking","affected_versions":"Python 3.12+"},{"fix":"If migrating, transition code incrementally. When running Eventlet on the `asyncio` hub, use provided APIs to explicitly wrap calls between Eventlet and `asyncio` contexts to ensure proper handling of concurrency primitives. Avoid direct inter-mixing where possible.","message":"Mixing Eventlet green threads with `asyncio`'s async functions has known limitations. Eventlet thread locals, `eventlet.greenthread.getcurrent()`, and Eventlet locks/queues may not work correctly when interacting directly between the two concurrency models in the same thread.","severity":"gotcha","affected_versions":"All"},{"fix":"Profile memory usage under load. Consider batching tasks, optimizing greenlet creation, and, for long-term solutions, migrating to `asyncio` or `trio` which often offer more refined resource management.","message":"Eventlet's green threads can lead to excessive memory consumption and inefficient resource management, especially under heavy loads or in large-scale applications, contributing to performance bottlenecks.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}