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-125828 : Fix 'get_value' missing on [Bounded]Semaphore on multiprocessing MacOSX#125829

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:semaphore-macosx-multiprocessing

Conversation

YvesDup
Copy link
Contributor

@YvesDupYvesDup commentedOct 22, 2024
edited by bedevere-appbot
Loading

This proposal is a workaround to fix absence of 'sem_getvalue' C function in the Semaphore MacOSX implementation.

Alls unit tests succeed except ontest.test_concurrent_futures.test_init relative to the Resource Tracker manager.

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

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

Is there an alternative way to do it without a temporary class like this? (I don't have the answer but I feel it overcomplicates the code base)

# Specific MacOSX Semaphore
#

class _MacOSXSemaphore(SemLock):
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to handle the SemLock class differently at the C level?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Wouldn't it be better to handle the SemLock class differently at the C level?

As I mentioned in the problem, I'm waiting for feedback (from the Mac OS team ?) before going any further.

A C implementation is an option, even if it seems more complicated than Python.
That said, I'm available to go deep into the SemLock C code

Copy link
Member

Choose a reason for hiding this comment

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

Actually, since the SemLock class is implemented in C, it's preferrable to first patch it there IMO. But let's CC some people I know they are on macOS:@ned-deily@ronaldoussoren@freakboy3742.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't profess any particular expertise in this area. However, given the underlying implementation is written in C, I agree that it makes some sense for the implementation of this workaround to also be in C (rather than have an underlying implementation that returns NotImplemented, wrapped by a layer that overrides that.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

rather than have an underlying implementation that returns NotImplemented, wrapped by a layer that overrides that.

The main idea is to listen to theacquire andrelease methods to update a shared counter, and to return the counter value when theget_value method is invoked.

I am going to open a new PR with a workaround written in C.

Comment on lines +140 to +141
util.debug(f"_MacOSXSemaphore:: creation of a {self.__class__.__name__}"\
f"with '{value = }'")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
util.debug(f"_MacOSXSemaphore:: creation of a{self.__class__.__name__}"\
f"with'{value=}'")
util.debug(f"_MacOSXSemaphore:: creation of a{self.__class__.__name__}"\
f"with{value=!r}")

def _acquire(self, *args, **kwargs) -> bool:
if self._semlock.acquire(*args, **kwargs):
with self._count:
util.debug(f"_MacOSXSemaphore: acquire {repr(self)}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
util.debug(f"_MacOSXSemaphore: acquire{repr(self)}")
util.debug(f"_MacOSXSemaphore: acquire{self!r}")

with self._count:
self._count.value += 1
self._semlock.release()
util.debug(f"_MacOSXSemaphore: release {repr(self)}")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
util.debug(f"_MacOSXSemaphore: release{repr(self)}")
util.debug(f"_MacOSXSemaphore: release{self!r}")

@ZeroIntensity
Copy link
Member

This needs a NEWS entry :)

YvesDup reacted with thumbs up emoji

@ronaldoussoren
Copy link
Contributor

Isget_value part of the public API for these classes? The name suggests it is, but the method is not document in the reference docs and does not have a docsstring.

I haven't looked with enough detail at the code to be certain, and am not a multiprocessing expert, but I the code doesn't seem correct. In particular, how does the implementation handle blocking callers of acquire when the count is 0 but not when it is larger than 0?

@YvesDup
Copy link
ContributorAuthor

YvesDup commentedNov 4, 2024
edited
Loading

isget_value part of the public API for these classes? The name suggests it is, but the method is not document in the reference docs and does not have a docsstring.

Yes, it is and I confirm this is not documented. This public method is rarely used to get a value of semaphore, except in unit tests. I should open an issue about this case.

In particular, how does the implementation handle blocking callers of acquire when the count is 0 but not when it is larger than 0?

As I explain itabove, this class only listen toacquire andrelease to update shared counter and then call respectivelyacquire andreleasemethods of_semlock class. Whenget_value is invoked, the class returns the counter value, and never calls thesemlock._get_value method (which raises NotImplementedError).

In this way, the behaviour of semaphores is always done at a low level in the implementation of thesemlockclass in the semaphore module (at C level).

@YvesDupYvesDup changed the titlegh-125828 : Fix 'get_value' missing on [Bouded]Semaphore on multiprocessing MacOSXgh-125828 : Fix 'get_value' missing on [Bounded]Semaphore on multiprocessing MacOSXNov 4, 2024
@YvesDupYvesDup deleted the semaphore-macosx-multiprocessing branchApril 11, 2025 13:47
@YvesDupYvesDup restored the semaphore-macosx-multiprocessing branchApril 11, 2025 13:47
@YvesDupYvesDup reopened thisApr 13, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@freakboy3742freakboy3742freakboy3742 left review comments

@picnixzpicnixzpicnixz left review comments

@gpsheadgpsheadAwaiting requested review from gpsheadgpshead is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@YvesDup@ZeroIntensity@ronaldoussoren@freakboy3742@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp