The Python Oracle

Google App Engine deferred.defer() failing when method returns

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Flying Over Ancient Lands

--

Chapters
00:00 Question
00:52 Accepted answer (Score 10)
01:16 Answer 2 (Score 2)
01:55 Thank you

--

Full question
https://stackoverflow.com/questions/4924...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #googleappengine #exception #task

#avk47



ACCEPTED ANSWER

Score 10


You should use:

result = deferred.defer(meeple_tasks.buildGames)

If you use buildGames(), that invokes the function right then and there, passing the return value to defer(). By removing the parenthesis, you pass the function itself to defer.




ANSWER 2

Score 2


You need to call your deferred task like this:

deferred.defer(meeple_tasks.buildGames)

"obj must be callable" means that (in your case) the value True is not callable. How I wrote the deferred call with "defer" the buildGames method call to another process (or task) by inserting it in a queue and letting the AppEngine framework deal with it.

Note that you cannot return anything with deferred tasks. They will be running on a different process and probably on a totally different server. As per the documentation they are Background workers.