Skip to content

[Backport maintenance/2.13.x] Add Lock to multiprocessing #1996

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

Merged
merged 1 commit into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Release date: TBA

Closes PyCQA/pylint#8074

* Add ``Lock`` to the ``multiprocessing`` brain.

Closes PyCQA/pylint#3313


What's New in astroid 2.13.3?
=============================
Expand Down
1 change: 1 addition & 0 deletions astroid/brain/brain_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class SyncManager(object):
Queue = JoinableQueue = queue.Queue
Event = threading.Event
RLock = threading.RLock
Lock = threading.Lock
BoundedSemaphore = threading.BoundedSemaphore
Condition = threading.Condition
Barrier = threading.Barrier
Expand Down
2 changes: 1 addition & 1 deletion astroid/brain/brain_threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __exit__(self, *args):
def locked(self):
return False

def Lock():
def Lock(*args, **kwargs):
return lock()
"""
)
Expand Down
5 changes: 5 additions & 0 deletions tests/unittest_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ def test_multiprocessing_manager(self) -> None:
joinable_queue = manager.JoinableQueue()
event = manager.Event()
rlock = manager.RLock()
lock = manager.Lock()
bounded_semaphore = manager.BoundedSemaphore()
condition = manager.Condition()
barrier = manager.Barrier()
Expand All @@ -736,6 +737,10 @@ def test_multiprocessing_manager(self) -> None:
rlock_name = "threading._RLock"
self.assertEqual(rlock.qname(), rlock_name)

lock = next(module["lock"].infer())
lock_name = "threading.lock"
self.assertEqual(lock.qname(), lock_name)

bounded_semaphore = next(module["bounded_semaphore"].infer())
semaphore_name = "threading.BoundedSemaphore"
self.assertEqual(bounded_semaphore.qname(), semaphore_name)
Expand Down