Skip to content

Multiprocessing Lock and RLock - invalid representation string on MacOSX. #125679

Closed
@YvesDup

Description

@YvesDup

Bug report

Bug description:

Due of absence of the sem_getvalue C function in the MacOSX semaphore implementation, Lock and RLock representation strings are invalid in the multiprocessing module.

Call to self._semlock._get_value() raises an exception, and set part of repr with 'unknown'.

import multiprocessing as mp
print(mp.Lock()     #  <Lock(owner=unknown)> vs <Lock(owner=None)> on Linux
print(mp.RLockj())  #  <RLock(unknown, unknown)> vs <RLock(None, 0)> on Linux

I propose to replace in the __repr__ method of each class the following test:

elif self._semlock._get_value() == 1:

elif self._semlock._get_value() == 1:

with elif not self._semlock._is_zero():.

This method is available and valid on each OS.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions