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

gh-133146: Add the old publicget_value method to documentation and refactor code.#133301

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
YvesDup wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
fromYvesDup:sem-macosx-multiprocessing-get_value
Open
Show file tree
Hide file tree
Changes fromall 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
7 changes: 7 additions & 0 deletionsDoc/library/multiprocessing.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1521,6 +1521,13 @@ object -- see :ref:`multiprocessing-managers`.
A solitary difference from its close analog exists: its ``acquire`` method's
first argument is named *block*, as is consistent with :meth:`Lock.acquire`.

.. method:: get_value()

Return the current value of semaphore.

Note that this may raise :exc:`NotImplementedError` on platforms like
macOS where ``sem_getvalue()`` is not implemented.

.. note::

On macOS, ``sem_timedwait`` is unsupported, so calling ``acquire()`` with
Expand Down
2 changes: 1 addition & 1 deletionLib/multiprocessing/queues.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -121,7 +121,7 @@ def get(self, block=True, timeout=None):

def qsize(self):
# Raises NotImplementedError on Mac OSX because of broken sem_getvalue()
return self._maxsize - self._sem._semlock._get_value()
return self._maxsize - self._sem.get_value()

def empty(self):
return not self._poll()
Expand Down
13 changes: 9 additions & 4 deletionsLib/multiprocessing/synchronize.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -135,11 +135,16 @@ def __init__(self, value=1, *, ctx):
SemLock.__init__(self, SEMAPHORE, value, SEM_VALUE_MAX, ctx=ctx)

def get_value(self):
'''Returns current value of Semaphore.

Raises NotImplementedError on Mac OSX
because of broken sem_getvalue().
'''
Comment on lines +138 to +142
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This file has no docstring. Should we remove this one ?

return self._semlock._get_value()

def __repr__(self):
try:
value = self._semlock._get_value()
value = self.get_value()
except Exception:
value = 'unknown'
return '<%s(value=%s)>' % (self.__class__.__name__, value)
Expand All@@ -155,7 +160,7 @@ def __init__(self, value=1, *, ctx):

def __repr__(self):
try:
value = self._semlock._get_value()
value = self.get_value()
except Exception:
value = 'unknown'
return '<%s(value=%s, maxvalue=%s)>' % \
Expand DownExpand Up@@ -247,8 +252,8 @@ def _make_methods(self):

def __repr__(self):
try:
num_waiters = (self._sleeping_count._semlock._get_value() -
self._woken_count._semlock._get_value())
num_waiters = (self._sleeping_count.get_value() -
self._woken_count.get_value())
except Exception:
num_waiters = 'unknown'
return '<%s(%s, %s)>' % (self.__class__.__name__, self._lock, num_waiters)
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Document the old public :meth:`get_value<multiprocessing.synchronized.Semaphore>`. Replace code using private attributes with this public method in ``multiprocessing.synchronized.py`` and ``multiprocessing.queues.py`` files

[8]ページ先頭

©2009-2025 Movatter.jp