[Twisted-Python] deferToThread and trial
Piper Masden
piper.masden at gmail.com
Fri May 30 00:13:58 MDT 2014
I have some Klein code that uses deferToThread for I/O. It looks something
like this:
@app.route('/', methods=['GET']
def index(request, *args, **kwargs):
d = deferToThread(some_blocking_db_select_function)
def serialize(db_object):
return json.dumps({
'id': db_object,
})
d.addCallback(serialize)
return d
I have a test that executes this function, and the deferToThread returns a
Deferred, but that deferred never fires its callback, and so when I use
successResultOf expecting a success result, no result is found.
When I use twistd to run the Klein application, everything works fine (the
deferred fires and I get a json string in the body of the response). What's
different about the trial environment that deferToThread might not fire its
callback? Do I need to explicitly set up a thread pool in trial that I
don't have to set up using twistd? Any help would be appreciated.
-Piper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20140530/faa694f7/attachment.html>
More information about the Twisted-Python
mailing list