【问题标题】:Are there limits to what you can do inside asynchronous URL fetch callbacks?您可以在异步 URL 获取回调中执行的操作是否有限制?
【发布时间】:2010-09-07 22:10:03
【问题描述】:

我正在尝试使用异步 URL 获取接口。但是当在生产环境中使用回调时,我得到一个 AssertionError。

这是由回调函数中的数据存储访问引起的吗?回调函数有什么限制?是否还有其他无法异步运行的 API?

这是堆栈...

('The Wait() request was interrupted by an exception from another callback:', AssertionError('1',))
Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/webapp/__init__.py", line 513, in __call__
    handler.post(*groups)
  File "/base/data/home/apps/smsmybus/15.344643308619037909/main.py", line 153, in post
    self.get()
  File "/base/data/home/apps/smsmybus/15.344643308619037909/main.py", line 182, in get
    bus.aggregateBusesAsynch(smsBody,self.request.get('SmsSid'),self.request.get('From'))
  File "/base/data/home/apps/smsmybus/15.344643308619037909/bus.py", line 296, in aggregateBusesAsynch
    rpc.wait()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 460, in wait
    self.__rpc.Wait()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 112, in Wait
    rpc_completed = self._WaitImpl()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/runtime/apiproxy.py", line 108, in _WaitImpl
    rpc_completed = _apphosting_runtime___python__apiproxy.Wait(self)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/runtime/apiproxy.py", line 171, in __MakeCallDone
    self.__Callback()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_rpc.py", line 161, in __Callback
    self.callback()
  File "/base/data/home/apps/smsmybus/15.344643308619037909/bus.py", line 265, in <lambda>
    return lambda: handle_result(rpc,stopID,routeID,sid,directionID)
  File "/base/data/home/apps/smsmybus/15.344643308619037909/bus.py", line 252, in handle_result
    stop.put()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/ext/db/__init__.py", line 893, in put
    return datastore.Put(self._entity, rpc=rpc)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 291, in Put
    'datastore_v3', 'Put', req, datastore_pb.PutResponse(), rpc)
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/datastore.py", line 194, in _MakeSyncCall
    rpc.wait()
  File "/base/python_runtime/python_lib/versions/1/google/appengine/api/apiproxy_stub_map.py", line 461, in wait
    assert self.__rpc.state == apiproxy_rpc.RPC.FINISHING, repr(self.state)
InterruptedError: ('The Wait() request was interrupted by an exception from another callback:', AssertionError('1',))

【问题讨论】:

  • 请求完成后是否调用了回调?例如,当这段代码运行时,你的主脚本执行完毕了吗?
  • 实际上我不确定...有没有什么技巧可以强制它等待所有回调?我宁愿不要在 for 循环中调用等待,因为它们可以按任何顺序返回。
  • 终于回到了这个问题上……你是对的,尼克。我试图在请求完成后执行回调。异步 URL 获取是一个很棒的功能。希望我能早点发现这一点。

标签: google-app-engine urlfetch


【解决方案1】:

添加我自己的答案只是为了结束这个......

尼克是对的。我尝试在请求完成后执行回调。我没有正确使用等待调用。

【讨论】:

    猜你喜欢
    • 2013-06-20
    • 1970-01-01
    • 2015-04-24
    • 2019-01-30
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多