There are the two rules that you've to keep in mind while working with gen.coroutine:
gen.coroutine decorated functions will automatically return a Future.
- If a function/coroutine is calling another coroutine decorated with
gen.coroutine, it must also be decorated with gen.coroutine and must use the yield keyword to get its result.
detailproduct is decorated with gen.coroutine - which means it will always return the datafromlib wrapped in a Future.
How to fix
According to Rule 2, you've to decorate the caller with gen.coroutine and use the yield keyword to get the result of the Future.
@gen.coroutine
def my_func():
data = yield detailproduct(url)
# do something with the data ...
OR
You can set a callback function on the Future that will be called when it gets resolved. But it makes the code messy.
def my_fun():
data_future = detailproduct(url)
data_future.add_done_callback(my_callback)
def my_callback(future):
data = future.result()
# do something with the data ...