python / python/cpython

Improve `__repr__` string of synchronize tools in the `multiprocessing` module.

Open
#155,092 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-multiprocessing type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

To be consistant with representation string of threading sychronize tools and in accordance with the discussion from the #149447 PR , the missing id information must be added in the __repr__ of the following synchronization classes:

  • Lock, Rlock,
  • Semaphore, BoundedSemaphore,
  • Condition.

and refactoring must be performed to these 2 classes:

  • Event,
  • Barrier.

See some examples below:

import threading
import multiprocessing

print(threading.Semaphore(3))
print(multiprocessing.Semaphore(3))

print(threading.Lock())
print(multiprocessing.Lock())

print(threading.Event())
print(multiprocessing.Event())

print(threading.Barrier(2))
print(multiprocessing.Barrier(2))

The ouput is:

<threading.Semaphore at 0x10378c8a0: value=3>
<Semaphore(value=3)>
<unlocked _thread.lock object at 0x103612040>
<Lock(owner=None)>
<threading.Event at 0x10378ccc0: unset>
<Event at 0x10378ccc0 unset>
<threading.Barrier at 0x10378ccc0: waiters=0/2>
<multiprocessing.synchronize.Barrier at 0x10378ccc0: waiters=0/2>

A PR will be published soon.

cc @gpshead

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:

#149447

Linked PRs
  • gh-155593

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the multiprocessing module with the Lock, Rlock, Semaphore, BoundedSemaphore, Condition, Event, and Barrier classes, comparing their representations with threading and the discussion in #149447. Done means the requested id information is included for the listed synchronization tools and Event and Barrier receive the proposed refactoring; note that PR #155593 is already linked in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.