Crochet is an MIT-licensed library that makes it easier for blocking or threaded applications like Flask or Django to use the Twisted networking framework. Crochet provides the following features:
* Runs Twisted's reactor in a thread it manages. * The reactor shuts down automatically when the process' main thread finishes. * Hooks up Twisted's log system to the Python standard library logging framework. Unlike Twisted's built-in logging bridge, this includes support for blocking Handler instances. * A blocking API to eventual results (i.e. Deferred instances). This last feature can be used separately, so Crochet is also useful for normal Twisted applications that use threads.
*Trivial Example *
""" Download a web page in a blocking manner. """
from __future__ import print_function
from twisted.web.client import getPage from crochet import setup, wait_for_reactor setup()
@wait_for_reactor def download_page(url): return getPage(url)
# download_page() now behaves like a normal blocking function: print(download_page(sys.argv))
*What's New in 1.1.0*
* EventualResult.wait() can now be used safely from multiple threads, thanks to Gavin Panella for reporting the bug. * Fixed reentrancy deadlock in the logging code caused by http://bugs.python.org/issue14976, thanks to Rod Morehead for reporting the bug. * Crochet now installs on Python 3.3 again, thanks to Ben Cordero. * Crochet should now work on Windows, thanks to Konstantinos Koukopoulos. * Crochet tests can now run without adding its absolute path to PYTHONPATH or installing it first.
* EventualResult.original_failure is now documented.