Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python.announce > #1290
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <itamar@itamarst.org> |
| X-Original-To | python-announce-list@python.org |
| Delivered-To | python-announce-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; '"""': 0.07; 'sys': 0.07; '__name__': 0.09; 'line:': 0.09; 'lookup': 0.09; 'release,': 0.09; 'url:github': 0.09; 'api': 0.11; 'python': 0.11; 'django': 0.11; 'def': 0.12; "'__main__':": 0.16; '->': 0.16; '__future__': 0.16; 'api,': 0.16; 'apis.': 0.16; 'backwards': 0.16; 'blocking': 0.16; 'cleanly': 0.16; 'container.': 0.16; 'easily,': 0.16; 'manner,': 0.16; 'parts.': 0.16; 'running:': 0.16; 'to:addr:python-announce-list': 0.16; 'twisted': 0.16; 'wsgi': 0.16; 'code.': 0.18; 'library': 0.18; 'unlike': 0.19; 'command': 0.22; 'example': 0.22; 'import': 0.22; 'install': 0.23; 'setup,': 0.24; 'downloaded': 0.26; 'function': 0.29; 'feature': 0.29; 'raise': 0.29; 'code': 0.31; 'easier': 0.31; 'requests': 0.31; 'filed': 0.31; 'yourself.': 0.31; 'interface': 0.32; 'regular': 0.32; 'run': 0.32; 'url:python': 0.33; 'bugs': 0.33; 'call.': 0.33; 'cases': 0.33; 'framework': 0.33; 'skip:# 10': 0.33; 'skip:d 20': 0.34; 'but': 0.35; 'interact': 0.36; 'useful': 0.36; 'url:org': 0.36; 'should': 0.36; 'seconds': 0.37; 'application': 0.37; 'project': 0.37; 'easily': 0.37; 'being': 0.38; 'to:addr:python.org': 0.39; 'users': 0.40; 'include:': 0.61; 'name': 0.63; 'more': 0.64; 'skip:r 30': 0.69 |
| X-Virus-Scanned | amavisd-new at kolabsys.net |
| X-Spam-Flag | NO |
| X-Spam-Score | 1.995 |
| X-Spam-Level | * |
| X-Spam-Status | No, score=1.995 tagged_above=-10 required=6.31 tests=[HTML_MESSAGE=0.001, MIME_HEADER_CTYPE_ONLY=1.996, NO_RECEIVED=-0.001, NO_RELAYS=-0.001] autolearn=no |
| Sender | itamar@itamarst.org |
| Date | Sat, 31 May 2014 16:08:35 -0400 |
| From | Itamar Turner-Trauring <itamar@itamarst.org> |
| To | python-announce-list@python.org |
| Subject | Crochet 1.3.0 - Use Twisted Anywhere! |
| X-Mailman-Approved-At | Mon, 02 Jun 2014 09:44:40 +0200 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Content-Filtered-By | Mailman/MimeDel 2.1.15 |
| X-BeenThere | python-announce-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | Announcement-only list for the Python programming language <python-announce-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-announce-list/> |
| List-Post | <mailto:python-announce-list@python.org> |
| List-Help | <mailto:python-announce-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe> |
| Approved | python-announce-list@python.org |
| Newsgroups | comp.lang.python.announce |
| Message-ID | <mailman.10544.1401695082.18130.python-announce-list@python.org> (permalink) |
| Lines | 69 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1401695082 news.xs4all.nl 2878 [2001:888:2000:d::a6]:34478 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python.announce:1290 |
Show key headers only | View raw
Crochet is an MIT-licensed library that makes it easier to use Twisted
from regular blocking code. Some use cases include:
* Easily use Twisted from a blocking framework like Django or Flask.
* Write a library that provides a blocking API, but uses Twisted for
its implementation.
* Port blocking code to Twisted more easily, by keeping a backwards
compatibility layer.
* Allow normal Twisted programs that use threads to interact with
Twisted more cleanly from their threaded parts. For example this can
be useful when using Twisted as a WSGI container.
This is a bugfix release, recommended for all users of Crochet.
Crochet can be downloaded from https://pypi.python.org/pypi/crochet or
by running:
$ pip install crochet
Documentation can be found at http://crochet.readthedocs.org
<https://crochet.readthedocs.org/>
Bugs and feature requests should be filed at the project
https://github.com/itamarst/crochet
Here’s an example of a program using Crochet. Notice that you get a
completely blocking interface to Twisted and do not need to run the
Twisted reactor, the event loop, yourself.
#!/usr/bin/python
"""
Do a DNS lookup using Twisted's APIs.
"""
from __future__ import print_function
# The Twisted code we'll be using:
from twisted.names import client
from crochet import setup, wait_for
setup()
# Crochet layer, wrapping Twisted's DNS library in a blocking call.
@wait_for(timeout=5.0)
def gethostbyname(name):
"""Lookup the IP of a given hostname.
Unlike socket.gethostbyname() which can take an arbitrary amount of time
to finish, this function will raise crochet.TimeoutError if more than 5
seconds elapse without an answer being received.
"""
d = client.lookupAddress(name)
d.addCallback(lambda result: result[0][0].payload.dottedQuad())
return d
if __name__ == '__main__':
# Application code using the public API - notice it works in a normal
# blocking manner, with no event loop visible:
import sys
name = sys.argv[1]
ip = gethostbyname(name)
print(name, "->", ip)
Run on the command line:
> $ python blockingdns.py twistedmatrix.com
> twistedmatrix.com -> 66.35.39.66
Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread
Crochet 1.3.0 - Use Twisted Anywhere! Itamar Turner-Trauring <itamar@itamarst.org> - 2014-05-31 16:08 -0400
csiph-web