Skip to content

[ENH]: Turn widgets.LockDraw into a context manager #24703

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

Closed
timhoffm opened this issue Dec 12, 2022 · 4 comments · May be fixed by thiagoluisbecker/matplotlib#1
Closed

[ENH]: Turn widgets.LockDraw into a context manager #24703

timhoffm opened this issue Dec 12, 2022 · 4 comments · May be fixed by thiagoluisbecker/matplotlib#1

Comments

@timhoffm
Copy link
Member

Problem

lock(obj)
...
lock.release(obj)

will not release the lock properly if an exception occurs in between.

Proposed solution

We therefore should aim at

with lock(obj):
    ...

by implementing __enter__ and __exit__.

Alternative: I'm quite unsure what the owner/available mechanism brings here. If that was not needed, we could use a standard threading.Lock.

@anntzer
Copy link
Contributor

anntzer commented Jan 2, 2023

We never actually call .release() in the same function as where we acquire the lock, so the contextmanager doesn't really help here.
The owner object is there to allow the same object to acquire a given lock multiple times (acquiring a second time is a noop), but I agree we should probably just check carefully all call sites to see whether that's actually a functionality we need.

@thiagoluisbecker
Copy link
Contributor

Hello @timhoffm! I'm trying to work in this issue and i'm not currently finding any occurrences of this in the codebase. This issue need to be work on the present version? If there are any occurrences plese tell me that I will enjoy to do it. Thank you!

@thiagoluisbecker
Copy link
Contributor

Hi! I implemented these enter and exit methods in the LockDraw Class at widgets.py. There is enough to turn it on a context manager? Also, In exit is necessary to verify if is in the right state? Thank you!

Captura de tela 2023-05-19 141245

@timhoffm
Copy link
Member Author

timhoffm commented Feb 2, 2025

It’s not clear this is actually helpful.

@timhoffm timhoffm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants