Google App Engine deferred.defer () does not work when method returns

I am trying to use google.appengine.ext.deferred to run a task. I pass the method to defer (), and this method succeeds, but a ValueError is thrown after it returns:

  File ".../admin.py", line 73, in post
    result = deferred.defer(meeple_tasks.buildGames())
      File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/deferred/deferred.py", line 198, in _curry_callable
        raise ValueError("obj must be callable")
    ValueError: obj must be callable

Here I call defer:

result = deferred.defer(meeple_tasks.buildGames())   

buildGames () will return True after completion.

+3
source share
2 answers

You should use:

result = deferred.defer(meeple_tasks.buildGames)

If you use buildGames()one that calls the function on the right then and there, passing the return value to defer(). By removing the bracket, you pass in a function to defer.

+10
source

You need to name your deferred task as follows:

deferred.defer(meeple_tasks.buildGames)

"obj " , ( ) True . "" buildGames ( ), AppEngine.

, - . , , . , .

+2

Source: https://habr.com/ru/post/1790513/


All Articles