See the waiting_for_handlers and waiting_for_handlers_and_compensation Python samples added in temporalio/samples-python#144, which feature a utility function like this:
def is_workflow_exit_exception(e: BaseException) -> bool:
"""
True if the exception is of a type that will cause the workflow to exit.
This is as opposed to exceptions that cause a workflow task failure, which
are retried automatically by Temporal.
"""
# 👉 If you have set additional failure_exception_types you should also
# check for these here.
return isinstance(e, (asyncio.CancelledError, exceptions.FailureError))