Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
Labels
type-featureA feature request or enhancement
@dcollison

Description

@dcollison

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()exceptBaseException:_lock.release()raisedef_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp