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
_______________________________________________
Twisted-Python mailing list
Twisted-Python@twistedmatrix.com
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

Reply via email to