diff --git a/docs/polyglot/python.md b/docs/polyglot/python.md index 785904c85f0..eeda51843ba 100644 --- a/docs/polyglot/python.md +++ b/docs/polyglot/python.md @@ -909,6 +909,19 @@ Workflow code is replayed from history. It must not perform any non-deterministi All non-determinism must flow through the context or be captured with `ctx.side_effect()`. +#### Finally blocks and context managers {#workflow-cleanup} + +**SDK 2.12.2 and later.** A suspension is not a workflow exit. Python may execute +`finally` blocks and `with` exits while disposing of a suspended replay. The SDK +discards durable commands and `ctx.logger` messages produced only by disposal; +queries see the state at the pending command. Actual completion, failure or +cooperative cancellation runs cleanup through the normal history, and cold +replay uses its recorded results. + +Keep direct I/O out of these hooks. Schedule external cleanup as an Activity +with `yield ctx.schedule_activity(...)`, and wrap that Activity in +`with ctx.cancellation_shield():` if it must finish after cooperative cancellation. + ### Fan-Out Yield a list of commands to run them concurrently: diff --git a/i18n/de/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/de/docusaurus-plugin-content-docs/current/polyglot/python.md index 5140de8ffbd..2b0d64b0c45 100644 --- a/i18n/de/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/de/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -879,6 +879,21 @@ Workflow-Code wird aus der Historie wiedergegeben. Er darf keine nicht determini Jeder Nichtdeterminismus muss über den Kontext laufen oder mit `ctx.side_effect()` erfasst werden. +#### Finally-Blöcke und Kontextmanager {#workflow-cleanup} + +**SDK 2.12.2 und höher.** Eine Unterbrechung ist kein Verlassen des Workflows. +Beim Freigeben eines angehaltenen Replays kann Python `finally`-Blöcke und +`with`-Austritte ausführen. Das SDK verwirft dauerhafte Befehle und Meldungen von +`ctx.logger`, die nur durch dieses Freigeben entstehen; Abfragen sehen den +Zustand am wartenden Befehl. Ein tatsächlicher Abschluss, Fehler oder +kooperativer Abbruch führt die Bereinigung über die normale Historie aus; +ein kaltes Replay nutzt die aufgezeichneten Ergebnisse. + +Führen Sie in diesen Blöcken keine direkte E/A aus. Planen Sie externe +Bereinigung als Aktivität mit `yield ctx.schedule_activity(...)` und umschließen +Sie diese Aktivität mit `with ctx.cancellation_shield():`, wenn sie nach einem +kooperativen Abbruch abgeschlossen werden muss. + ### Auffächerung {#fan-out} Geben Sie eine Liste von Befehlen aus, um sie nebenläufig auszuführen: diff --git a/i18n/de/source-hashes.json b/i18n/de/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/de/source-hashes.json +++ b/i18n/de/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/es/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/es/docusaurus-plugin-content-docs/current/polyglot/python.md index 84d925896c3..8a012cefde3 100644 --- a/i18n/es/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/es/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -858,6 +858,20 @@ no deterministas: Todo no determinismo debe pasar por el contexto o capturarse con `ctx.side_effect()`. +#### Bloques finally y gestores de contexto {#workflow-cleanup} + +**SDK 2.12.2 y posteriores.** Una suspensión no equivale a salir del workflow. +Al descartar una reproducción suspendida, Python puede ejecutar los bloques +`finally` y las salidas de `with`. El SDK descarta los comandos duraderos y los +mensajes de `ctx.logger` producidos únicamente por ese descarte; las consultas +observan el estado en el comando pendiente. La finalización real, un fallo o +la cancelación cooperativa ejecutan la limpieza mediante el historial normal; +la reproducción en frío utiliza los resultados registrados. + +Evita operaciones de E/S directas en esos bloques. Programa la limpieza externa +como una actividad con `yield ctx.schedule_activity(...)` y envuélvela en +`with ctx.cancellation_shield():` si debe terminar tras la cancelación cooperativa. + ### Ejecución en paralelo {#fan-out} Produce una lista de comandos para ejecutarlos concurrentemente: diff --git a/i18n/es/source-hashes.json b/i18n/es/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/es/source-hashes.json +++ b/i18n/es/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/fr/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/fr/docusaurus-plugin-content-docs/current/polyglot/python.md index 30bc98e5c70..2d175b41321 100644 --- a/i18n/fr/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/fr/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -877,6 +877,20 @@ opération non déterministe directement : Tout non-déterminisme doit passer par le contexte ou être capturé avec `ctx.side_effect()`. +#### Blocs finally et gestionnaires de contexte {#workflow-cleanup} + +**SDK 2.12.2 et versions ultérieures.** Une suspension n'est pas une sortie du +workflow. Lors de la libération d'une relecture suspendue, Python peut exécuter +les blocs `finally` et les sorties de `with`. Le SDK ignore les commandes +durables et les messages de `ctx.logger` produits uniquement par cette +libération ; les requêtes de lecture observent l'état au niveau de la commande +en attente. Une fin, un échec ou une annulation coopérative réels exécutent le +nettoyage via l'historique normal ; la relecture à froid utilise les résultats enregistrés. + +Évitez les E/S directes dans ces blocs. Planifiez le nettoyage externe comme +une activité avec `yield ctx.schedule_activity(...)` et encadrez cette activité +par `with ctx.cancellation_shield():` si elle doit se terminer après l'annulation coopérative. + ### Distribution parallèle {#fan-out} Émettez une liste de commandes avec yield pour les exécuter simultanément : diff --git a/i18n/fr/source-hashes.json b/i18n/fr/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/fr/source-hashes.json +++ b/i18n/fr/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/ja/docusaurus-plugin-content-docs/current/polyglot/python.md index 0b0826b58f8..dc3e780afb1 100644 --- a/i18n/ja/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/ja/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -725,6 +725,19 @@ receipt = yield ctx.schedule_activity( 非決定的な処理はすべてコンテキスト経由にするか、`ctx.side_effect()` で記録する必要があります。 +#### finally ブロックとコンテキストマネージャー {#workflow-cleanup} + +**SDK 2.12.2 以降。** 中断はワークフローからの終了を意味しません。中断したリプレイを +破棄するとき、Python は `finally` ブロックや `with` の終了処理を実行することがあります。 +SDK は破棄だけが原因で発生した永続コマンドと `ctx.logger` のログを破棄し、クエリは +待機中のコマンドの時点の状態を参照します。実際の完了、失敗、協調的キャンセルでは +通常の履歴に従ってクリーンアップを実行し、コールドリプレイでは記録済みの結果を使用します。 + +これらのブロックで直接 I/O を行わないでください。外部のクリーンアップは +`yield ctx.schedule_activity(...)` でアクティビティとしてスケジュールします。 +協調的キャンセル後も完了させる必要がある場合は、そのアクティビティを +`with ctx.cancellation_shield():` で囲んでください。 + ### ファンアウト {#fan-out} 並行実行するにはコマンドのリストを yield します。 diff --git a/i18n/ja/source-hashes.json b/i18n/ja/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/ja/source-hashes.json +++ b/i18n/ja/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/pt-BR/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/pt-BR/docusaurus-plugin-content-docs/current/polyglot/python.md index 7c37824c52a..d5b2c4c9e8e 100644 --- a/i18n/pt-BR/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/pt-BR/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -878,6 +878,19 @@ operações não determinísticas: Todo não determinismo deve passar pelo contexto ou ser capturado com `ctx.side_effect()`. +#### Blocos finally e gerenciadores de contexto {#workflow-cleanup} + +**SDK 2.12.2 e posteriores.** Uma suspensão não é uma saída do workflow. Durante +o descarte de um replay suspenso, o Python pode executar blocos `finally` e as +saídas de `with`. O SDK descarta comandos duráveis e mensagens de `ctx.logger` +gerados apenas por esse descarte; as consultas veem o estado no comando +pendente. A conclusão, a falha ou o cancelamento cooperativo reais executam a +limpeza pelo histórico normal; o replay a frio utiliza os resultados registrados. + +Evite E/S direta nesses blocos. Agende a limpeza externa como uma atividade com +`yield ctx.schedule_activity(...)` e envolva essa atividade em +`with ctx.cancellation_shield():` se ela precisar terminar após o cancelamento cooperativo. + ### Fan-out {#fan-out} Produza uma lista de comandos com yield para executá-los concorrentemente: diff --git a/i18n/pt-BR/source-hashes.json b/i18n/pt-BR/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/pt-BR/source-hashes.json +++ b/i18n/pt-BR/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/uk/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/uk/docusaurus-plugin-content-docs/current/polyglot/python.md index a65528caf70..52e78ddb564 100644 --- a/i18n/uk/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/uk/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -865,6 +865,19 @@ receipt = yield ctx.schedule_activity( Уся недетермінованість має проходити через контекст або фіксуватися `ctx.side_effect()`. +#### Блоки finally та контекстні менеджери {#workflow-cleanup} + +**SDK 2.12.2 і новіші.** Призупинення не є виходом із workflow. Під час знищення +призупиненого replay Python може виконати блоки `finally` і виходи з `with`. +SDK відкидає стійкі команди й повідомлення `ctx.logger`, що виникли лише через +це знищення; query бачить стан на команді очікування. Справжнє завершення, +помилка або кооперативне скасування виконують очищення через звичайну історію, +а холодний replay використовує записані результати. + +Не виконуйте прямий I/O в цих обробниках. Плануйте зовнішнє очищення як activity +через `yield ctx.schedule_activity(...)` та обгорніть цю activity у +`with ctx.cancellation_shield():`, якщо вона має завершитися після кооперативного скасування. + ### Паралельне розгалуження {#fan-out} Передайте через yield список команд для паралельного виконання: diff --git a/i18n/uk/source-hashes.json b/i18n/uk/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/uk/source-hashes.json +++ b/i18n/uk/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1", diff --git a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/polyglot/python.md b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/polyglot/python.md index 8e9d27a7725..16e21c10a3b 100644 --- a/i18n/zh-Hans/docusaurus-plugin-content-docs/current/polyglot/python.md +++ b/i18n/zh-Hans/docusaurus-plugin-content-docs/current/polyglot/python.md @@ -711,6 +711,17 @@ receipt = yield ctx.schedule_activity( 所有非确定性必须通过上下文或用 `ctx.side_effect()` 捕获。 +#### finally 代码块与上下文管理器 {#workflow-cleanup} + +**SDK 2.12.2 及更高版本。** 暂停并不表示工作流已经退出。丢弃已暂停的重放时, +Python 仍可能执行 `finally` 代码块和 `with` 的退出逻辑。SDK 会丢弃仅由这次清理 +产生的持久化命令和 `ctx.logger` 日志;查询看到的是等待中的命令所在位置的状态。 +真正的完成、失败或协作式取消会按正常历史执行清理;冷重放会使用已记录的结果。 + +不要在这些代码块中直接执行 I/O。通过 `yield ctx.schedule_activity(...)` 将外部清理 +安排为活动;若该活动必须在协作式取消后完成,请用 `with ctx.cancellation_shield():` +包裹它。 + ### 扇出 {#fan-out} yield 命令列表以并发运行: diff --git a/i18n/zh-Hans/source-hashes.json b/i18n/zh-Hans/source-hashes.json index 98aecac1bad..d35cba7e212 100644 --- a/i18n/zh-Hans/source-hashes.json +++ b/i18n/zh-Hans/source-hashes.json @@ -82,7 +82,7 @@ "polyglot/polling-patterns.md": "30875099a23731c6c471b481a771378acc6ff57eed2fda4405a509057534c989", "polyglot/portable-worker-affinity.md": "40973c6a31a76845b4f95e9a505e68ad76abd5174bbdccf37993cdebc8904959", "polyglot/prerelease-history-migration.md": "a57f05f492228a8a67791f9152648a1e5f80856325b78777cf63b6ef49b7413c", - "polyglot/python.md": "1908679d0a02c538dbcc6aed41715799b1b7b89d67e9517b4bf3658196174dd5", + "polyglot/python.md": "7778dab32c706188d446ed61e6c971e200d3e750fdfb6ebf077d63bfe7f5623f", "polyglot/rust-cloud-quickstart.md": "2303434fc9302a81a8381ad4836423ef9952eb3201a4574c432254e3cb68c5f3", "polyglot/rust.md": "af91b22c93a7fe6833df156371d99bb105740684915bc73af4576f6de2897e10", "polyglot/server-api-reference.md": "b0a7bfa17ccaec0507ee97dfc1badac49fa5ff96f8178fa4ce5963bc8c6fe7d1",