Debian Codegraph @

doc/source/asyncio/guide/awaitlet.rst

raw
1 .. _awaitlet_alternative:
2
3 Awaitlet as an Alternative
4 ==========================
5
6 Applications with several years of existence may have seen their code base
7 growing again and again, thus, migrating this kind of existing code
8 base toward AsyncIO, would be painful or even unrealistic. For most of these
9 applications, migrating to AsyncIO would may mean a complete rewriting of
10 these applications.
11
12 `Awaitlet <https://awaitlet.sqlalchemy.org/en/latest/>`_ is an alternative
13 which allow you to migrate this kind of existing code base without getting
14 the headaches associated to migrating such deliverables.
15
16 Awaitlet allows existing programs written to use threads and blocking APIs to
17 be ported to asyncio, by replacing frontend and backend code with asyncio
18 compatible approaches, but allowing intermediary code to remain completely
19 unchanged, with no addition of ``async`` or ``await`` keywords throughout the
20 entire codebase needed. Its primary use is to support code that is
21 cross-compatible with asyncio and non-asyncio runtime environments.
22
23 Awaitlet is a direct extract of `SQLAlchemy <https://www.sqlalchemy.org/>`_’s
24 own asyncio mediation layer, with no dependencies on SQLAlchemy. This code has
25 been in widespread production use in thousands of environments for several
26 years.
27
28 .. warning::
29
30 Using Awaitlet require to use the :mod:`Asyncio Hub
31 <eventlet.hubs.asyncio>`
32
33 :ref:`understanding_hubs`
34
35 Here is an example of Awaitlet usage::
36
37 import asyncio
38 import awaitlet
39
40 def asyncio_sleep():
41 return awaitlet.awaitlet(asyncio.sleep(5, result='hello'))
42
43 print(asyncio.run(awaitlet.async_def(asyncio_sleep)))
44
45 We invite the reader to read the `Awaitlet synopsis
46 <https://awaitlet.sqlalchemy.org/en/latest/synopsis.html>`_ to get a better
47 overview of the opportunities offered by this library.