Use Twisted anywhere!
Crochet is an MIT-licensed library that makes it easier to use Twisted from regular blocking code. Some use cases include:
WSGI container_... _WSGI container: https://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html
Crochet is maintained by Itamar Turner-Trauring.
Note: Crochet development is pretty slow these days because mostly it Just Works. PyPI shows about 30,000 downloads a month, so existing users seem happy: https://pypistats.org/packages/crochet
You can install Crochet by running::
$ pip install crochet
Downloads are available on PyPI_.
Documentation can be found on Read The Docs_.
Bugs and feature requests should be filed at the project Github page_.
.. _Read the Docs: https://crochet.readthedocs.org/ .. _Github page: https://github.com/itamarst/crochet/ .. _PyPI: https://pypi.python.org/pypi/crochet
Crochet supports Python 3.8, 3.9, 3.10, and 3.11 as well as PyPy3.
Crochet provides the following basic APIs:
crochet.wait_for decorator.crochet.run_in_reactor) allows blocking code to run
code "in the background" in the Twisted thread, with the ability to repeatedly
check if it's done.Crochet will do the following on your behalf in order to enable these APIs:
logging
framework. Unlike Twisted's built-in logging bridge, this includes
support for blocking Handler instances.2.1.0 ^^^^^
2.0.0 ^^^^^
New features:
async/await Twisted functions with @wait_for and @run_in_reactor, thanks to Árni Már Jónsson.Removed features:
@wait_for_reactor, @in_reactor, DeferredResult, the wrapped_function attribute, and unlimited timeouts on EventualResult.wait().1.12.0 ^^^^^^
Bug fixes:
1.11.0 ^^^^^^
New features:
Backwards incompatibility:
1.10.0 ^^^^^^
New features:
1.9.0 ^^^^^
New features:
@run_in_reactor and @wait_for is now available via the more standard __wrapped__ attribute.Backwards incompatibility (in tests):
wrapped_function may not always be available on decorated callables.
You should use __wrapped__ instead.Bug fixes:
1.8.0 ^^^^^
New features:
Bug fixes:
@run_in_reactor and @wait_for above a @classmethod.
Thanks to vak for the bug report.1.7.0 ^^^^^
Bug fixes:
logging.Handler throws an exception Crochet no longer goes into a death spiral.
Thanks to Michael Schlenker for the bug report.Removed features:
1.6.0 ^^^^^
New features:
1.5.0 ^^^^^
New features:
Removed features:
1.4.0 ^^^^^
New features:
Documentation:
Bug fixes:
1.3.0 ^^^^^
Bug fixes:
EventualResult.wait() (or functions
wrapped in wait_for) at import time if another thread holds the
import lock. Thanks to Ken Struys for the patch.1.2.0 ^^^^^ New features:
crochet.wait_for implements the timeout/cancellation pattern documented
in previous versions of Crochet. crochet.wait_for_reactor and
EventualResult.wait(timeout=None) are now deprecated, since lacking
timeouts they could potentially block forever.wait_for and run_in_reactor can now be accessed
via the wrapped_function attribute, to ease unit testing of the underlying
Twisted code.API changes:
EventualResult.wait() (or functions
wrapped with wait_for) at import time, since this can lead to deadlocks
or prevent other threads from importing. Thanks to Tom Prince for the bug
report.Bug fixes:
warnings are no longer erroneously turned into Twisted log messages.crochet.setup() or
crochet.no_setup() are called, allowing daemonization if only crochet
is imported (http://tm.tl/7105). Thanks to Daniel Nephin for the bug report.Documentation:
1.1.0 ^^^^^ Bug fixes:
EventualResult.wait() can now be used safely from multiple threads,
thanks to Gavin Panella for reporting the bug.Documentation:
EventualResult.original_failure is now documented.1.0.0 ^^^^^ Documentation:
Bug fixes:
setup.py, thanks to
Paul Weaver for bug report and Chris Scutcher for patch.0.9.0 ^^^^^ New features:
@wait_for_reactor added, a simpler alternative to
@run_in_reactor.@run_in_reactor, making it a bit more responsive.EventualResult.wait() or @wait_for_reactor decorated call)
will be interrupted with a ReactorStopped exception. Thanks to rmorehead
for the bug report.Bug fixes:
@run_in_reactor decorated functions (or rather, their generated wrapper)
are interrupted by Ctrl-C.reactor.spawnProcess have their exit noticed. See Twisted ticket 6378_
for more details about the underlying issue... _Twisted ticket 6378: http://tm.tl/6738
0.8.1 ^^^^^
EventualResult.wait() now raises error if called in the reactor thread,
thanks to David Buchmann.EventualResult.wait(timeout=None).0.7.0 ^^^^^
0.6.0 ^^^^^
DeferredResult to EventualResult, to reduce confusion with
Twisted's Deferred class. The old name still works, but is deprecated.@in_reactor, replaced with @run_in_reactor which doesn't
change the arguments to the wrapped function. The deprecated API still works,
however.EventualResult objects are logged.setup.py sdist should work now.0.5.0 ^^^^^