Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #2107 > unrolled thread

Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else

Started byItamar Turner-Trauring <itamar@itamarst.org>
First post2016-04-13 16:18 -0400
Last post2016-04-13 16:18 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python.announce

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else Itamar Turner-Trauring <itamar@itamarst.org> - 2016-04-13 16:18 -0400

#2107 — Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else

FromItamar Turner-Trauring <itamar@itamarst.org>
Date2016-04-13 16:18 -0400
SubjectCrochet 1.5.0: Use Twisted in Django, Flask, or anywhere else
Message-ID<mailman.87.1460581033.15650.python-announce-list@python.org>
Do you wish you could:

  * Use the power of Twisted's asynchronous networking in Django, Flask,
    or other threaded applications?
  * Provide a blocking API powered by Twisted underneath, without
    exposing it to the caller?
  * Write a library that provides APIs both for Twisted and non-Twisted
    applications?
  * Use threads more easily inside Twisted applications?

Crochet lets you do all that, and more, by hiding and automatically 
starting the Twisted reactor and providing a blocking API for calling 
into Twisted. If you need to use your library from a normal Twisted 
application you can disable the auto-start functionality. Here's an 
example of using Twisted in a blocking manner:

from __future__ import print_function
from twisted.names import client
from crochet import setup, wait_for
setup()

@wait_for(timeout=5.0)
def gethostbyname(name):
      """Use the Twisted DNS library."""
      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)

New in 1.5.0 is official Python 3.5 support; Python 2.6, 3.3 and older 
versions of Twisted are no longer officially supported (but are likely 
to still work).

If you need help using Crochet (or just general Twisted or Python help) 
I am currently available for short-term consulting. You can read the 
documentation at https://crochet.readthedocs.org/.

--Itamar Turner-Trauring

[toc] | [standalone]


Back to top | Article view | comp.lang.python.announce


csiph-web