ndb.Tasklet and SyncTasklet with multiple nested functions
I'm trying to effectively call the tasklet and subtasks:
@ndb.tasklet
def getBeds(bed_key):
bed = yield bed_key.get_asyn()
bed_info = {}
......
raise ndb.Return(bed_info)
@ndb.tasklet
def getRoom(room_key):
room = yield room_key.get_async()
room_info = {}
..........
beds_in_room = map(getBeds,room.beds)
room_info["beds"] = beds_in_room
raise ndb.Return(room_info)
@ndb.tasklet
def getBuilding(build_key):
build = yield build_key.get_async()
build_info = {}
...........
rooms_in_build = map(getRoom,build.rooms)
build_info["rooms"] = rooms_in_build
@ndb.toplevel
def getHotel(hotel_obj)
hotel_inf = {}
.........
buildings_in_hotel = map(getBuilding,hotel_obj.buildings)
hotel_inf["buildings"] = buildings_in_hotel
return hotel_inf
For some reason, I thought @ ndb.toplevel would pause getHotel until it's over. Unfortunately building_in_hotel is returning a list of futures ...
How do I get it to complete?
+3
source to share
1 answer
You get!
When you call tasklet, you always get the future and then you get the result. There is also a parallel exit where you get a tuple or list of talismans (sometimes called barriers).
beds_in_room = yield map(getBeds,room.beds)
and
rooms_in_build = yield map(getRoom,build.rooms)
and
buildings_in_hotel = yield map(getBuilding,hotel_obj.buildings)
+3
source to share