#๐Ÿ”’ Pythonic way of returning multiple success/failure results?

18 messages ยท Page 1 of 1 (latest)

fast fog
#

I have a function that needs to perform some batch API calls. Some of these API calls may succeed and some may fail. Regardless, the caller function (that calls this function) needs to gather the results (which succeeded and which did not). What's the best / Pythonic way of doing this? Using exception? exception group? or just plain tuple returns?

Additionally, if I want to make the API calls async, what's the best way to return the (success/fail) results as the API calls are finished? Using yield?

wary jewelBOT
#

@fast fog

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fast fog
#

Pythonic way for function to return multiple success/failure results?

placid siren
#

so you want to deliver the results in an unordered fashion, each one as soon as they're completed?

fast fog
placid siren
dreamy musk
#

Probably you want a TaskGroup and a Queue

#

Put results in the Queue and let failures raise

fast fog
#

And let the function returns 2 Queues to the caller?

#

I am not sure how to handle multiple exceptions asynchronously

fast fog
oblique shore
fast fog
oblique shore
#

in that case I would just have the task print them

#

no need so "save" anything

wary jewelBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.