Debian Codegraph @

docs/userguide/concurrency/gevent.rst

raw
1 .. _concurrency-eventlet:
2
3 ===========================
4 Concurrency with gevent
5 ===========================
6
7 .. _gevent-introduction:
8
9 Introduction
10 ============
11
12 The `gevent`_ homepage describes it a coroutine_ -based Python_ networking library that uses
13 `greenlet <https://greenlet.readthedocs.io>`_ to provide a high-level synchronous API on top of the `libev`_
14 or `libuv`_ event loop.
15
16 Features include:
17
18 * Fast event loop based on `libev`_ or `libuv`_.
19 * Lightweight execution units based on greenlets.
20 * API that reuses concepts from the Python standard library (for
21 examples there are `events`_ and
22 `queues`_).
23 * `Cooperative sockets with SSL support <http://www.gevent.org/api/index.html#networking>`_
24 * `Cooperative DNS queries <http://www.gevent.org/dns.html>`_ performed through a threadpool,
25 dnspython, or c-ares.
26 * `Monkey patching utility <http://www.gevent.org/intro.html#monkey-patching>`_ to get 3rd party modules to become cooperative
27 * TCP/UDP/HTTP servers
28 * Subprocess support (through `gevent.subprocess`_)
29 * Thread pools
30
31 gevent is `inspired by eventlet`_ but features a more consistent API,
32 simpler implementation and better performance. Read why others `use
33 gevent`_ and check out the list of the `open source projects based on
34 gevent`_.
35
36
37 Enabling gevent
38 =================
39
40 You can enable the gevent pool by using the
41 :option:`celery worker -P gevent` or :option:`celery worker --pool=gevent`
42 worker option.
43
44 .. code-block:: console
45
46 $ celery -A proj worker -P gevent -c 1000
47
48 .. _eventlet-examples:
49
50 Examples
51 ========
52
53 See the `gevent examples`_ directory in the Celery distribution for
54 some examples taking use of Eventlet support.
55
56 Known issues
57 ============
58 There is a known issue using python 3.11 and gevent.
59 The issue is documented `here`_ and addressed in a `gevent issue`_.
60 Upgrading to greenlet 3.0 solves it.
61
62 .. _events: http://www.gevent.org/api/gevent.event.html#gevent.event.Event
63 .. _queues: http://www.gevent.org/api/gevent.queue.html#gevent.queue.Queue
64 .. _`gevent`: http://www.gevent.org/
65 .. _`gevent examples`:
66 https://github.com/celery/celery/tree/main/examples/gevent
67 .. _gevent.subprocess: http://www.gevent.org/api/gevent.subprocess.html#module-gevent.subprocess
68
69 .. _coroutine: https://en.wikipedia.org/wiki/Coroutine
70 .. _Python: http://python.org
71 .. _libev: http://software.schmorp.de/pkg/libev.html
72 .. _libuv: http://libuv.org
73 .. _inspired by eventlet: http://blog.gevent.org/2010/02/27/why-gevent/
74 .. _use gevent: http://groups.google.com/group/gevent/browse_thread/thread/4de9703e5dca8271
75 .. _open source projects based on gevent: https://github.com/gevent/gevent/wiki/Projects
76 .. _what's new: http://www.gevent.org/whatsnew_1_5.html
77 .. _changelog: http://www.gevent.org/changelog.html
78 .. _here: https://github.com/celery/celery/issues/8425
79 .. _gevent issue: https://github.com/gevent/gevent/issues/1985