Running post tasks even if the main task fail

オープン
#980 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
cli

調査の方向性

Start by tracing how pre and post tasks are executed around main_task and how unhandled exceptions propagate. Define the failure-path behavior so my_post_task performs cleanup after main_task fails, then verify both successful and failing task runs.

索引モデルが issue の本文から書いたものです。

説明

Hello. I was wondering if there's a way to make sure that a post task runs even if the main task fails with an unhandled exception? Here's a simplified version of my code to illustrate the issue:

@task()
def my_pre_task(ctx):
    # Do some resource provisioning needed by the task


@task()
def my_post_task(ctx):
    # Perform resource cleanup
    # This should always run, but it won't if the main task fails with an unhandled exception


@task(pre=[my_pre_task], post=[my_post_task])
def main_task(ctx):
    # Do something that could also result in an unhandled exception

I know that I can wrap the main_task in a try/finally, but I'd rather not do this if I can find a more elegant solution. I was hoping there was something like post_run_on_failure=True that I could use, or a finally task that behaves like a post but always run.

主要言語
Python
スター
4.8k
フォーク
412
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pyinvoke/invoke のほかの issue

pyinvoke/invoke の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。