|
2 | 2 | Learn asyncio if you come from Twisted
|
3 | 3 | ++++++++++++++++++++++++++++++++++++++
|
4 | 4 |
|
5 |
| -`Twisted project <https://twistedmatrix.com/trac/>`_. |
| 5 | +The `Twisted project <https://twistedmatrix.com/trac/>`_ is probably one of the |
| 6 | +oldest libraries that supports asynchronous programming in Python. |
| 7 | +It has been used by many programmers to develop a variety of applications. |
| 8 | +It supports many network protocols and can be used for many different |
| 9 | +types of network programming. |
| 10 | +In fact, asyncio was heavily inspired by Twisted. |
| 11 | +The expertise of several Twisted developers had been incorporated in |
| 12 | +asyncio. |
| 13 | +Soon, there will be a version of Twisted that is based on asyncio. |
| 14 | + |
6 | 15 |
|
7 | 16 |
|
8 | 17 | Rosetta Stone
|
9 | 18 | =============
|
10 | 19 |
|
| 20 | +This tables shows equivalent concepts in Twisted and asyncio. |
| 21 | + |
11 | 22 | ======================== ==================================
|
12 | 23 | Twisted asyncio
|
13 | 24 | ======================== ==================================
|
14 |
| -Deferred asyncio.Future |
15 |
| -deferToThread(func) loop.run_in_executor(None, func) |
16 |
| -@inlineCallbacks async def |
17 |
| -reactor.run() loop.run_forever() |
| 25 | +``Deferred`` ``asyncio.Future`` |
| 26 | +``deferToThread(func)`` ``loop.run_in_executor(None, func)`` |
| 27 | +``@inlineCallbacks`` ``async def`` |
| 28 | +``reactor.run()`` ``loop.run_forever()`` |
18 | 29 | ======================== ==================================
|
19 | 30 |
|
20 | 31 |
|
21 | 32 | Deferred example
|
22 | 33 | ================
|
23 | 34 |
|
| 35 | +This small example shows two equivalent programs, one implemented in Twisted |
| 36 | +and one in asyncio. |
| 37 | + |
24 | 38 | +--------------------------------------------------+--------------------------------------------------+
|
25 | 39 | | Twisted | asyncio |
|
26 | 40 | +==================================================+==================================================+
|
|
0 commit comments