GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update logging library module lock to use context manager to acquire/release lock. · Issue #109461 · python/cpython

Update logging library module lock to use context manager to acquire/release lock. #109461

New issue
Copy link
New issue
Copy link
Closed
Closed
Update logging library module lock to use context manager to acquire/release lock.#109461
Copy link
Labels
type-featureA feature request or enhancementA feature request or enhancement

Description

@dcollison
dcollison
opened on Sep 15, 2023
Issue body actions

Feature or enhancement

Proposal:

Current implementation relies on both _acquireLock() and _releaseLock() being called, otherwise a lock may never be released:

def _acquireLock():
    """
    Acquire the module-level lock for serializing access to shared data.

    This should be released with _releaseLock().
    """
    if _lock:
        try:
            _lock.acquire()
        except BaseException:
            _lock.release()
            raise

def _releaseLock():
    """
    Release the module-level lock acquired by calling _acquireLock().
    """
    if _lock:
        _lock.release()

The majority of usages of _acquireLock() manually add a try/except/finally block to ensure that the lock is released if an exception is thrown. Some usages of _acquireLock() have no safety.

The proposal is to alter the usage of _acquireLock() to be a context manager that deals with acquiring and releasing automatically rather than requiring try/except/finally blocks to be used anywhere the function is called.

For example,
usage before:

_acquireLock()
try:
    ...
finally:
    _releaseLock()

proposed usage:

with _acquireLock():
    ...

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

  • gh-109461: Update logging module lock acquisition to use context manager #109462

Activity

  1. dcollison
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Sep 15, 2023
  2. dcollison
    added 14 commits that reference this issue on Sep 15, 2023

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    6664c4c

    Merge remote-tracking branch 'origin/pythongh-109461-update-logging-l…

    749b678

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    ea33592

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    af9f7d1

    Merge remote-tracking branch 'origin/pythongh-109461-update-logging-l…

    dc7df1e

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    a30d5da

    Merge remote-tracking branch 'origin/pythongh-109461-update-logging-l…

    0a53f3b

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    b5e6651

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    1b14732

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    600a126

    Merge remote-tracking branch 'origin/pythongh-109461-update-logging-l…

    20e46f6

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    df75801

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    c1a9651

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    efd7462
  3. AA-Turner
    added a commit that references this issue on Sep 26, 2023

    Merge branch 'main' into pythongh-109461-update-logging-lock-acquisition

    797ae0d
  4. vstinner
    added a commit that references this issue on Sep 27, 2023

    gh-109461: Update logging module lock to use context manager (#109462)

    74723e1
  5. csm10495
    added a commit that references this issue on Sep 28, 2023

    pythongh-109461: Update logging module lock to use context manager (p…

    e5576c0
  6. dcollison
    closed this as completedon Sep 28, 2023
  7. The-Compiler
    added a commit that references this issue on Jun 25, 2024

    tests: Update private logging API usage for Python 3.13

    d0cc8d4
  8. Glyphack
    added a commit that references this issue on Sep 2, 2024

    pythongh-109461: Update logging module lock to use context manager (p…

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.