The project I am working on is all written in Tornado, but I have included a bit of Twisted to deal with asynchronous XML-RPC. I was wondering if you can use Tornado's gen.engine and yield gen.Task with Twisted's code. Is this possible? If so how would the syntax look like? Thanks in advance.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
I modified Ben's sample code a bit in order to set exception correctly.
twisted wrap exception as a failure.Failure. future.set_exception complains it is not an exception type.
You can use
gen.Task
with anything that takes acallback
keyword argument. However, Twisted-style code usually returns aDeferred
instead of taking a callback as input. You'll need to wrap theDeferred
in somethingtornado.gen
can understand (probably aFuture
). Something like this (untested):Sure - but it's called
inlineCallbacks
in Twisted: