<div dir="ltr">I have some Klein code that uses deferToThread for I/O. It looks something like this:<div><br></div><div>@app.route('/', methods=['GET']</div><div>def index(request, *args, **kwargs):</div><div>
    d = deferToThread(some_blocking_db_select_function)</div><div><br></div><div>    def serialize(db_object):</div><div>        return json.dumps({</div><div>            'id': db_object,</div><div>            })</div>
<div>    d.addCallback(serialize)</div><div>    return d</div><div><br></div><div>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.</div>
<div><br></div><div>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.</div>
<div><br></div><div>-Piper</div></div>