def _set_final_result(self, response):
self._cancel_timer()
if self._metrics is not None:
self._metrics.request_timer.addValue(time.time() - self._start_time)
with self._callback_lock:
self._final_result = response
# save off current callbacks inside lock for execution outside it
# -- prevents case where _final_result is set, then a callback is
# added and executed on the spot, then executed again as a
# registered callback
to_call = tuple(
partial(fn, response, *args, **kwargs)
for (fn, args, kwargs) in self._callbacks
)
self._event.set()
# apply each callback
for callback_partial in to_call:
callback_partial()
评论列表
文章目录