Skip to content
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

Question: why locking countdowns? #2

Open
ghost opened this issue Nov 6, 2020 · 1 comment
Open

Question: why locking countdowns? #2

ghost opened this issue Nov 6, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Nov 6, 2020

Hi Łukasz

I followed your awesome PyCon talk. I did a few similar experiments and I just started to write some music with aiotone.

I have a question about this:

async with self.countdowns_lock:
self.countdowns.append(countdown)

I have used async back in the tornado days and didn't do much recently. I would only lock if the code was:

 async with self.lock: 
     await ...
     .....
     await ...

(Of course we had only yield)

Otherwise there is nothing that can run in between, right? I guess you write it like that in case you change the code to something more complex.

@ambv
Copy link
Owner

ambv commented Nov 6, 2020

You're right that this example it looks artificial without any await expressions inside the lock. You're also right that there might be future changes to code here and a surprise await might indeed change behavior of any of the three methods to become incorrect.

I was interested in expressing that "this should be atomic" in the transactional sense. While it's not strictly necessary, it worked in the context of the talks I was giving for which this code was originally written.

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

No branches or pull requests

1 participant