@defer.inlinecallbacks
def fetch_data(user_id):
r = yield treq.get('url/to/fetch/%s'%user_id)
text = yield r.text()
defer.returnValue(text)
@defer.inlinecallbacks
def fetch_recs(user_id):
data = yield fetch_data(user_id)
recs = {}
for stype in similar_types:
d = defer.ToThread(long_computation, *(stype, data)) // typo was here
Now, I do believe that the call is happening asyncronously. So.. yay..
But then, I feel like I have a misconception on how the yield works.
data = yield fetch_data(user_id)
I was hoping data here was actual data.. But it is a deferred.. Which makes sense.
And then.. this deferred is being passed on instead of the actual data...
My couple of questions are:
1) What is the difference between data = yield fetch_data(user_id) and data = fetch_data(user_id) (without yield). How does twisted handle these two ?
2) How do I actually send the data to long computation rather than a deferred.
Appreciate all the help.
Thanks