Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Um Future representa o resultado de uma operação assíncrona.
Quando criado, ele provavelmente não tem dados de resultado.
Quando a operação termina, o Future recebe o resultado.
Um aplicativo pode chamar o método get_result() de um objeto Future. Se o resultado tiver chegado, o método vai retorná-lo. Do contrário, ele aguarda a chegada do resultado e depois o retorna.
Observação: não há mapeamento 1:1 entre RPCs e Futures. Vários futures podem estar vinculados a um resultado de uma única RPC.
Métodos de instância
check_success()
Verifica se a operação foi bem-sucedida. Aguarda, se necessário.
Gera uma exceção quando há um problema. Caso contrário, retorna None.
done()
Retorna True se o resultado (ou a exceção) tiver chegado. Do contrário, retorna False. Essa função não aguarda.
get_exception()
Aguarda, se necessário. Em seguida, retorna a exceção (ou None caso não haja exceção). Retorna a exceção. Não a gera.
get_result()
Aguarda, se necessário. Em seguida, retorna o resultado ou gera a exceção.
get_traceback()
Aguarda, se necessário. Em seguida, retorna o objeto traceback da exceção (ou None caso não haja objeto traceback).
O módulo
traceback
do Python tem funções para imprimir e trabalhar com objetos traceback.
wait()
Aguarda até um resultado ou uma exceção chegar.
O retorno é sempre None.
Métodos de classe
wait_all(futures)
Aguarda a conclusão de todos os Futures no iterável passado.
Argumentos
futures
Iterável de objetos Future.
Retorna None.
wait_any(futures)
Aguarda a conclusão de pelo menos um dos iteráveis de Futures.
Argumentos
futures
Iterável de objetos Future.
Retorna um Future concluído.
(Retorna None se o iterável futures estiver vazio.)
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[[["\u003cp\u003eThis page outlines how to utilize legacy bundled services and APIs, which are exclusive to first-generation runtimes within the App Engine standard environment.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eFuture\u003c/code\u003e object represents the outcome of an asynchronous operation and stores the result once the operation is complete.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eFuture\u003c/code\u003e object includes methods like \u003ccode\u003eget_result()\u003c/code\u003e to retrieve the result, \u003ccode\u003echeck_success()\u003c/code\u003e to confirm the operation's success, and \u003ccode\u003edone()\u003c/code\u003e to check if the operation has finished.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003ewait_all\u003c/code\u003e and \u003ccode\u003ewait_any\u003c/code\u003e are class methods that allow you to wait for multiple \u003ccode\u003eFutures\u003c/code\u003e to complete, either waiting for all to finish or waiting until at least one is done.\u003c/p\u003e\n"]]],[],null,["# NDB Future Class\n\n| This page describes how to use the legacy bundled services and APIs. This API can only run in first-generation runtimes in the App Engine standard environment. If you are updating to the App Engine Python 3 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/python-differences) to learn about your migration options for legacy bundled services.\n\nA `Future` represents the result of an\n[asynchronous operation](/appengine/docs/legacy/standard/python/ndb/async).\nWhen created, it probably doesn't have any result data.\nWhen the operation finishes, the `Future` gets the result.\nAn application can call a `Future` object's\n`get_result()` method; if the result has arrived, the\nmethod returns it; otherwise, it waits for the result to arrive and\n*then* returns it.\n\n**Note:** There is no 1:1 mapping between RPCs and Futures. Multiple futures might be tied to a result from a single RPC.\n\nInstance Methods\n----------------\n\ncheck_success()\n: Check to see if the operation succeeded. Waits if necessary.\n Raises an exception if there was a problem; returns `None`\n if there was no problem.\n\ndone()\n: Returns `True` if the result (or exception) has arrived;\n otherwise, returns `False`. This function does not wait.\n\nget_exception()\n: Waits if necessary; then returns the exception (or `None` if\n there was no exception). *Returns* the exception, doesn't raise it.\n\nget_result()\n: Waits if necessary; then returns the result or raises the exception.\n\nget_traceback()\n: Waits if necessary; then returns the exception's traceback\n object (or `None` if there was no traceback object).\n Python's\n [traceback](http://docs.python.org/library/traceback.html) module has functions to print and work with\n traceback objects.\n\nwait()\n: Waits until a result or exception arrives.\n Always returns `None`.\n\nClass Methods\n-------------\n\nwait_all(futures)\n: Wait until all `Futures` in the passed iterable are done.\n\n **Arguments**\n\n futures\n : Iterable of `Future` objects.\n\n\n Returns `None`.\n\nwait_any(futures)\n: Wait until at least one of a iterable of `Futures` is done.\n\n **Arguments**\n\n futures\n : Iterable of `Future` objects.\n\n\n Returns one `Future` that is done.\n (Returns `None` if the `futures` iterable is empty.)"]]