python - Google App Engine deferred.defer() 在方法返回时失败

标签 python google-app-engine exception task

我正在尝试使用 google.appengine.ext.deferred 来运行任务。我正在将一个方法传递给 defer() 方法,该方法成功运行,但在返回时抛出一个 ValueError:

  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

这是我调用 defer 的地方:

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

buildGames() 完成后将返回 True。

最佳答案

你应该使用:

result = deferred.defer(meeple_tasks.buildGames)

如果您使用 buildGames(),它会立即调用函数,将返回值传递给 defer( )。通过删除括号,您将函数本身传递给 defer。

关于python - Google App Engine deferred.defer() 在方法返回时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4924648/

相关文章:

python - python/pythonpath 路径问题

python - 复制 numpy 数组的每第 n 列

google-app-engine - 如何克隆托管在 Google App Engine 上的网站?

java - 谷歌应用引擎编码

C#ArgumentOutOfRangeException异常

python - 如何在 Pandas 数据框中查找值

c++ - 是否可以在我的 C++ 程序中嵌入任何 Python 编辑控件?

android - 使用 Firebase 和 Google Cloud Messaging 推送通知

ios - 在主队列中设置属性时 Swift 应用程序崩溃

delphi - Delphi:神经网络类(TD-lambda)中的EInvalidOp