| 1 |
Use Twisted Anywhere! |
| 2 |
===================== |
| 3 |
.. raw:: html |
| 4 |
|
| 5 |
<div><a class="github-button" href="https://github.com/itamarst/crochet" data-icon="octicon-star" data-show-count="true" aria-label="Star itamarst/crochet on GitHub">Star</a> |
| 6 |
<script async defer src="https://buttons.github.io/buttons.js"></script></div> |
| 7 |
|
| 8 |
Crochet is an MIT-licensed library that makes it easier for blocking and |
| 9 |
threaded applications like Flask or Django to use the Twisted networking |
| 10 |
framework. |
| 11 |
|
| 12 |
Here's an example of a program using Crochet. Notice that you get a completely |
| 13 |
blocking interface to Twisted and do not need to run the Twisted reactor, the |
| 14 |
event loop, yourself. |
| 15 |
|
| 16 |
.. literalinclude:: ../examples/blockingdns.py |
| 17 |
|
| 18 |
Run on the command line:: |
| 19 |
|
| 20 |
$ python blockingdns.py twistedmatrix.com |
| 21 |
twistedmatrix.com -> 66.35.39.66 |
| 22 |
|
| 23 |
You can also wrap ``async`` functions. |
| 24 |
Here is the equivalent code to the previous example, but using an ``async/await`` function: |
| 25 |
|
| 26 |
.. code-block:: python |
| 27 |
|
| 28 |
@wait_for(timeout=5.0) |
| 29 |
async def gethostbyname(name): |
| 30 |
result = await client.lookupAddress(name) |
| 31 |
return result[0][0].payload.dottedQuad() |
| 32 |
|
| 33 |
Table of Contents |
| 34 |
^^^^^^^^^^^^^^^^^ |
| 35 |
|
| 36 |
.. toctree:: |
| 37 |
:maxdepth: 3 |
| 38 |
|
| 39 |
introduction |
| 40 |
api |
| 41 |
using |
| 42 |
type-checking |
| 43 |
workarounds |
| 44 |
async |
| 45 |
api-reference |
| 46 |
news |