Skip to content

port mutex sample from go repository #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

K-Yo
Copy link

@K-Yo K-Yo commented Jun 22, 2025

What was changed

Added a python sample for mutex pattern

Why?

The sample exists for go sdk but not for python yet. I needed it so I figured I could share it.

Checklist

  1. TODO

I’ve left a TODO in the code, I am not sure how to properly distinguish who sends a release in python (even if sender workflows are supposed to send them in order)

  1. How was this tested:

ran it locally with latest temporal dev server, and using branch pyproject.toml configuration.

  1. Any docs updates needed?

not that I think of

@K-Yo K-Yo requested a review from a team as a code owner June 22, 2025 10:31
@CLAassistant
Copy link

CLAassistant commented Jun 22, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

return f"unlock-event-{sender_workflow_id}"


@workflow.defn
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may not want to blind-port this from Go but have a more Pythonic way to do a mutex and we want to make sure workflows are in their own files separate from activities/models. For instance, the .NET version of this sample at https://github.com/temporalio/samples-dotnet/tree/main/src/Mutex made an idiomatic WorkflowMutex class for general purpose use. I think this sample should consider a workflow-backed Lock class that looks almost exactly like https://docs.python.org/3/library/asyncio-sync.html#asyncio.Lock and is copyable/usable as if it is a library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants