gevent

Coroutine-based network library

MIT 96 个版本 Python >=3.9
Denis Bilenko <denis.bilenko@gmail.com>
安装
pip install gevent
poetry add gevent
pipenv install gevent
conda install gevent
描述

======== gevent

.. image:: https://coveralls.io/repos/gevent/gevent/badge.svg?branch=master&service=github :target: https://coveralls.io/github/gevent/gevent?branch=master

.. This file is included in README.rst from the top-level so it is limited to pure ReST markup, not Sphinx.

gevent is a coroutine_ -based Python_ networking library that uses greenlet <https://greenlet.readthedocs.io>_ 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.
  • API that re-uses concepts from the Python standard library (for examples there are events_ and queues_).
  • Cooperative sockets with SSL support <http://www.gevent.org/api/index.html#networking>_
  • Cooperative DNS queries <http://www.gevent.org/dns.html>_ performed through a threadpool, dnspython, or c-ares.
  • Monkey patching utility <http://www.gevent.org/intro.html#monkey-patching>_ to get 3rd party modules to become cooperative
  • TCP/UDP/HTTP servers
  • Subprocess support (through gevent.subprocess_)
  • Thread pools

gevent is inspired by eventlet_ but features a more consistent API, simpler implementation and better performance. Read why others use gevent_ and check out the list of the open source projects based on gevent_.

gevent was written by Denis Bilenko <http://denisbilenko.com/>_.

Since version 1.1, gevent is maintained by Jason Madden for NextThought <https://nextthought.com>_ (through gevent 21) and Institutional Shareholder Services <https://www.issgovernance.com>_ with help from the contributors <https://github.com/gevent/gevent/graphs/contributors>_ and is licensed under the MIT license.

See what's new_ in the latest major release.

Check out the detailed changelog_ for this version.

.. _events: http://www.gevent.org/api/gevent.event.html#gevent.event.Event .. _queues: http://www.gevent.org/api/gevent.queue.html#gevent.queue.Queue .. _gevent.subprocess: http://www.gevent.org/api/gevent.subprocess.html#module-gevent.subprocess

.. _coroutine: https://en.wikipedia.org/wiki/Coroutine .. _Python: http://python.org .. _libev: http://software.schmorp.de/pkg/libev.html .. _libuv: http://libuv.org .. _inspired by eventlet: http://blog.gevent.org/2010/02/27/why-gevent/ .. _use gevent: http://groups.google.com/group/gevent/browse_thread/thread/4de9703e5dca8271 .. _open source projects based on gevent: https://github.com/gevent/gevent/wiki/Projects .. _what's new: http://www.gevent.org/whatsnew_1_5.html .. _changelog: http://www.gevent.org/changelog.html

Read the documentation online at http://www.gevent.org.

Post issues on the bug tracker, discuss and ask open ended questions on the mailing list, and find announcements and information on the blog_ and twitter (@gevent)_.

=============================== Installation and Requirements

.. _installation:

.. This file is included in README.rst so it is limited to plain ReST markup, not Sphinx.

.. note::

If you are reading this document on the Python Package Index_ (PyPI, https://pypi.org/), it is specific to the version of gevent that you are viewing. If you are viewing this document on gevent.org, it refers to the current state of gevent in source control (git master).

Supported Platforms

This version of gevent runs on Python 3.9 and up (for exact details of tested versions, see the classifiers on the PyPI page or in setup.py). gevent requires the greenlet <https://greenlet.readthedocs.io>_ library and will install the cffi_ library by default on Windows. The cffi library will become the default on all platforms in a future release of gevent.

This version of gevent is also tested on PyPy 3.10 (7.3.12); it should run on PyPy 3.9 and above. On PyPy, there are no external dependencies.

gevent is tested on Windows, macOS, and Linux, and should run on most other Unix-like operating systems (e.g., FreeBSD, Solaris, etc.)

.. note::

Windows is supported as a tier 2, "best effort," platform. It is suitable for development, but not recommended for production. In particular, PyPy3 on Windows may have issues, especially with subprocesses.

On Windows, using the deprecated libev backend, gevent is limited to a maximum of 1024 open sockets due to limitations in libev_. This limitation should not exist with the default libuv backend.

.. admonition:: Free-Threading is not Supported

Beginning with 3.14 (and experimental in 3.13), CPython may be built in a free-threaded mode where the GIL is not used by default. gevent does not support this mode (although it will build with it), and using gevent in such an interpreter will cause the GIL to be enabled.

The underlying greenlet library also has this limitation <https://greenlet.readthedocs.io/en/latest/caveats.html#free-threading-is-not-supported>_.

In addition, other limitations in greenlet mean that attempting to use gevent in a free-threaded interpreter is not recommended at this time. It is likely to work, but may have resource leaks.

Older Versions of Python

Users of older versions of Python 2 or Python 3 may install an older version of gevent. Note that these versions are generally not supported.

+-------+-------+ |Python |Gevent | |Version|Version| +=======+=======+ |2.5 |1.0.x | | | | +-------+-------+ |2.6 |1.1.x | +-------+-------+ |<= |1.2.x | |2.7.8 | | +-------+-------+ |3.3 |1.2.x | +-------+-------+ |3.4.0 -| 1.3.x | |3.4.2 | | | | | +-------+-------+ |3.4.3 | 1.4.x | | | | | | | +-------+-------+ |3.5.x | 20.9.0| | | | | | | +-------+-------+ |2.7.9 -| | |2.7.18,| 22.10 | |3.6, | | |3.7 | | | | | +-------+-------+ |3.8 | 24.2.1| +-------+-------+

Installation

.. note::

This section is about installing released versions of gevent as distributed on the Python Package Index. For building gevent from source, including customizing the build and embedded libraries, see Installing From Source.

.. _Python Package Index: http://pypi.org/project/gevent

gevent and greenlet can both be installed with pip, e.g., pip install gevent. Installation using buildout <http://docs.buildout.org/en/latest/> is also supported.

On Windows, macOS, and Linux, both gevent and greenlet are distributed as binary wheels_.

.. tip::

You need Pip 8.0 or later, or buildout 2.10.0, to install the binary wheels on Windows or macOS. On Linux, you'll need pip 19 <https://github.com/pypa/pip/pull/5008>_ to install the manylinux2010 wheels.

.. tip::

While the x86-64 binaries are considered production quality, they are built with relatively low optimization levels and no hardware specific optimizations. Serious production users are encouraged to install from source with appropriate compiler flags.

.. tip::

Beginning with gevent 20.12.0, 64-bit ARM binaries are distributed on PyPI for aarch64 manylinux2014 compatible systems. Installing these needs a very recent version of pip. These wheels do not contain the c-ares resolver, are not tested, and are built with very low levels of optimization. Serious production users of gevent on 64-bit ARM systems are encouraged to build their own binary wheels.

Beginning with gevent 22.10.0, ppc64le binaries are distributed on PyPI. The same caveats apply as for 64-bit ARM binaries. Using them for anything other than local development is discouraged.

Beginning with gevent 23, muslinux aarch64 and S390X binaries are distributed on PyPI. The same caveats apply as for 64-bit ARM binaries. Using them for anything other than local development is discouraged.

Installing From Source

If you are unable to use the binary wheels (for platforms where no pre-built wheels are available or if wheel installation is disabled), you can build gevent from source. A normal pip install will fall back to doing this if no binary wheel is available. See Installing From Source_ for more, including common installation issues.

Extra Dependencies

There are a number of additional libraries that extend gevent's functionality and will be used if they are available. All of these may be installed using setuptools extras <https://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies>_, as named below, e.g., pip install gevent[events].

events In versions of gevent up to and including 20.5.0, this provided configurable event support using zope.event <https://pypi.org/project/zope.event>_ and was highly recommended.

In versions after that, this extra is empty and does nothing. It
will be removed in gevent 21.0.

dnspython Enables a pure-Python resolver, backed by dnspython <https://pypi.org/project/dnspython>. On Python 2, this also includes idna <https://pypi.org/project/idna>. They can be installed with the dnspython extra.

.. note:: This is not compatible with Python 3.10+ or dnspython 2.

monitor Enhancements to gevent's self-monitoring capabilities. This includes the psutil <https://pypi.org/project/psutil>_ library, which is needed to monitor memory usage. (Note that this may not build on all platforms.)

recommended A shortcut for installing suggested extras together. This includes the non-test extras defined here, plus additions that improve gevent's operation on certain platforms (for example, in the past, it has included backports of newer APIs).

test Everything needed to run the complete gevent test suite.

.. _pip: https://pip.pypa.io/en/stable/installing/ .. _wheels: http://pythonwheels.com .. _gevent 1.5: whatsnew_1_5.html .. _Installing From Source: https://www.gevent.org/development/installing_from_source.html

.. _cffi: https://cffi.readthedocs.io .. _limitations in libev: http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#WIN32_PLATFORM_LIMITATIONS_AND_WORKA

.. _bug tracker: https://github.com/gevent/gevent/issues .. _mailing list: http://groups.google.com/group/gevent .. _blog: https://dev.nextthought.com/blog/categories/gevent.html .. _twitter (@gevent): http://twitter.com/gevent

版本列表
26.5.0 2026-05-20
26.4.0 2026-04-08
25.9.1 2025-09-17
25.8.2 2025-08-29
25.8.1 2025-08-28
25.5.1 2025-05-12
25.4.2 2025-04-24
25.4.1 2025-04-17
24.11.1 2024-11-11
24.10.3 2024-10-18
24.10.2 2024-10-11
24.10.1 2024-10-09
24.2.1 2024-02-14
23.9.1 2023-09-12
23.9.0 2023-09-01
23.9.0.post1 2023-09-02
23.7.0 2023-07-11
22.10.2 2022-10-31
22.10.1 2022-10-14
22.8.0 2022-10-08
21.12.0 2021-12-11
21.8.0 2021-08-05
21.1.2 2021-01-20
21.1.1 2021-01-18
21.1.0 2021-01-15
20.12.1 2020-12-27
20.12.0 2020-12-22
20.9.0 2020-09-22
20.6.2 2020-06-16
20.6.1 2020-06-10
20.6.0 2020-06-06
20.5.2 2020-05-28
20.5.1 2020-05-26
20.5.0 2020-05-01
20.4.0 2020-04-22
1.5.0 2020-04-10
1.4.0 2019-01-04
1.3.7 2018-10-12
1.3.6 2018-08-17
1.3.5 2018-07-16
1.3.4 2018-06-20
1.3.3 2018-06-08
1.3.2 2018-05-29
1.3.2.post0 2018-05-30
1.3.1 2018-05-18
1.3.0 2018-05-11
1.2.2 2017-06-05
1.2.1 2017-01-12
1.2.0 2017-01-04
1.1.2 2016-07-21
1.1.1 2016-04-04
1.1.0 2016-03-05
1.0.2 2015-09-24
1.0.1 2014-04-30
1.0 2013-11-26
1.5a4 2020-03-25
1.5a3 2020-01-01
1.5a2 2019-10-22
1.5a1 2019-05-02
1.3b2 2018-05-03
1.3b1 2018-04-13
1.3a2 2018-03-06
1.3a1 2018-01-27
1.2a2 2016-12-09
1.2a1 2016-10-27
1.1rc5 2016-02-24
1.1rc4 2016-02-16
1.1rc3 2016-01-04
1.1rc2 2015-12-11
1.1rc1 2015-11-14
1.1b6 2015-10-17
1.1b5 2015-09-18
1.1b4 2015-09-04
1.1b3 2015-08-16
1.1b2 2015-08-05
1.1b1 2015-07-17
1.1a2 2015-07-08
1.1a1 2015-06-29
0.13.8 2012-09-06
0.13.7 2012-04-12
0.13.6 2011-05-02
0.13.5 2011-04-21
0.13.4 2011-04-11
0.13.3 2011-02-07
0.13.2 2011-01-28
0.13.1 2010-09-23
0.13.0 2010-07-14
0.12.2 2010-03-02
0.12.1 2010-02-26
0.12.0 2010-02-05
0.11.2 2009-12-10
0.11.1 2009-11-15
0.11.0 2009-10-09
0.10.0 2009-08-26
0.9.3 2009-08-03
0.9.2 2009-07-20