temporalio / temporalio/sdk-python

[Feature Request] Improve wait_condition semantics

Open
#618 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
1.2k
Forks
241
Avg merge
3d 21h
Merged PRs (30d)
55

Description

Ideally, the following would not happen:

@workflow.defn
class WaitForSharedMutableStateWorkflow:
    def __init__(self) -> None:
        self.cond = False

    @workflow.run
    async def run(self):
        self.cond = True
        await asyncio.gather(self.coro("1"), self.coro("2"))

    async def coro(self, id: str):
        await workflow.wait_condition(lambda: self.cond)
        print(f"after wait coro {id} sees {self.cond}")  # ❗❗ <== coro2 sees False❗
        self.cond = False
        await asyncio.sleep(1)
        self.cond = True

Completely eliminating the possibility would be ideal, but best-effort improvements would also be welcome.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the workflow.wait_condition example with asyncio.gather and the two coro calls shown in the issue, then inspect how wait_condition resumes concurrent workflows. Define and document the intended behavior for shared mutable state; done means the demonstrated coro2 sees False case is eliminated, or a clearly specified best-effort behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.