Skip to content

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

Closed as not planned
thiagoluisbecker/matplotlib
#1

Description

@timhoffm

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.

Activity

  1. anntzer commented on Jan 2, 2023

    @anntzer
    Contributor

    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.

  2. thiagoluisbecker commented on May 3, 2023

    @thiagoluisbecker
    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!

  3. thiagoluisbecker commented on May 19, 2023

    @thiagoluisbecker
    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

  4. timhoffm commented on Feb 2, 2025

    @timhoffm
    MemberAuthor

    It’s not clear this is actually helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions